Example usage for android.widget LinearLayout getVisibility

List of usage examples for android.widget LinearLayout getVisibility

Introduction

In this page you can find the example usage for android.widget LinearLayout getVisibility.

Prototype

@ViewDebug.ExportedProperty(mapping = { @ViewDebug.IntToString(from = VISIBLE, to = "VISIBLE"),
        @ViewDebug.IntToString(from = INVISIBLE, to = "INVISIBLE"),
        @ViewDebug.IntToString(from = GONE, to = "GONE") })
@Visibility
public int getVisibility() 

Source Link

Document

Returns the visibility status for this view.

Usage

From source file:com.github.colorchief.colorchief.MainActivity.java

@Override
public boolean dispatchTouchEvent(MotionEvent event) {

    LinearLayout overlayColorControl = (LinearLayout) findViewById(R.id.overlayColorControl);
    ImageButton buttonImageClose = (ImageButton) findViewById(R.id.buttonImageClose);
    ImageView imageView = (ImageView) findViewById(R.id.imageView);

    if (event.getAction() == MotionEvent.ACTION_UP) {

        if (buttonImageClose.getVisibility() == View.VISIBLE) {
            if (clickInButtonImageClose((int) event.getX(), (int) event.getY())) {
                closeImage((View) findViewById(R.id.imageView));
            }//from www. j  ava  2  s.  c o  m
        }

        if ((overlayColorControl.getVisibility() == View.INVISIBLE)
                && (((TabHost) findViewById(R.id.tabHost)).getCurrentTab() == 0)) {

            if (clickInImage((int) event.getX(), (int) event.getY(), imageView)) {

                if (bitmapLoaded) {
                    int imagePixelLocation[] = clickImagePixelLocation((int) event.getX(), (int) event.getY(),
                            imageView);
                    clickColourChange(imagePixelLocation[0], imagePixelLocation[1], imageView);
                } else {
                    openImageFile(imageView);
                }

            }
        }
    }

    return super.dispatchTouchEvent(event);
}

From source file:com.equinox.prodriver.Activities.RegisterDriverActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_register_driver);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);/*from  w  w  w. ja v a2 s  .c  o  m*/
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    context = this;
    appBarLayout = (AppBarLayout) findViewById(R.id.app_bar);
    appBarLayout.setExpanded(false, true);
    mainScrollView = (NestedScrollView) findViewById(R.id.content_register_driver);
    mainScrollView.setSmoothScrollingEnabled(true);
    selectorsLayouts = new ArrayList<>();

    editDriver = new Driver();
    preferredPlace = new PrologixPlace();
    if (currentDriver == null) {
        getSupportActionBar().setTitle(getString(R.string.title_activity_register_driver));
        if (savedInstanceState != null && savedInstanceState.getBoolean("EDITING")) {
            editDriver = tempDriver;
            if (editDriver == null)
                editDriver = new Driver();
        }
        vehiclesList = new ArrayList<>();
    } else {
        getSupportActionBar().setTitle(getString(R.string.title_activity_update_driver));
        editDriver = currentDriver.clone();
        if (editDriver.getPreferredAddress() != null) {
            preferredPlace.setAddress(
                    driverGson.fromJson(driverGson.toJson(editDriver.getPreferredAddress()), GeoAddress.class));
            preferredPlace.setLocation(
                    driverGson.fromJson(driverGson.toJson(editDriver.getPreferredLocation()), LatLng.class));
        }
    }

    storagePermission = new PermissionManager(this);
    if (!storagePermission.checkReadStoragePermission())
        storagePermission.getReadStoragePermission();
    registerEmailHeaderFragment = RegisterEmailHeaderFragment.newInstance(editDriver);

    vehicleIndicator = (ImageView) findViewById(R.id.driver_vehicle_indicator);
    if (editDriver.getVehicles() == null)
        editDriver.setVehicles(new ArrayList<Vehicle>());
    vehicleRecyclerAdapter = new VehicleRecyclerAdapter(context, editDriver.getVehicles(), false);
    if (!editDriver.getVehicles().isEmpty())
        setIndicator(context, vehicleIndicator, true);
    if (!editDriver.getVehicles().contains(createVehicle)) {
        editDriver.getVehicles().add(new Vehicle());
        //TODO remove this.. just for testing only
        /*String vehicleId = "SA-3184VLB";
        DriverTask driverTask = new DriverTask(vehicleFetcher, "en");
        driverTask.getVehicle.execute(vehicleId);*/
    }
    vehicleListView = (RecyclerView) findViewById(R.id.vehicle_list_view);
    vehicleListView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
    vehicleListView.setHasFixedSize(true);
    vehicleListView.setAdapter(vehicleRecyclerAdapter);
    vehicleListView.setNestedScrollingEnabled(false);

    licenseIndicator = (ImageView) findViewById(R.id.license_info_indicator);
    licenseValueNumber = (TextView) findViewById(R.id.license_info_number);
    licenseValueExpiry = (TextView) findViewById(R.id.license_info_expiry);
    licenseImage = (ImageView) findViewById(R.id.license_image);
    licenseImageLoaded = (NetworkImageView) findViewById(R.id.license_image_loaded);
    licenseInfoLayout = (RelativeLayout) findViewById(R.id.license_info_layout);
    if (editDriver.getLicenseNumber() != null) {
        setIndicator(context, licenseIndicator, true);
        licenseValueNumber.setText(editDriver.getLicenseNumber());
        licenseValueExpiry.setText(StringManipulation.getFormattedDate(editDriver.getLicenseExpiry()));
        if (editDriver.getLicenseImage() != null)
            licenseImageLoaded.setImageUrl(editDriver.getLicenseImage(),
                    DataHolder.getInstance().getImageLoader());
    }
    if (photo1 != null)
        licenseImage.setImageBitmap(photo1);
    licenseInfoLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent scanIdIntent = new Intent(context, CameraVisionActivity.class);
            scanIdIntent.putExtra("source", REQUEST_DRIVER_LICENSE);
            startActivity(scanIdIntent);
        }
    });

    residenceIndicator = (ImageView) findViewById(R.id.residence_info_indicator);
    residenceValueNumber = (TextView) findViewById(R.id.residence_info_number);
    residenceValueExpiry = (TextView) findViewById(R.id.residence_info_expiry);
    residenceValueLegalName = (TextView) findViewById(R.id.residence_info_legal_name);
    residenceImage = (ImageView) findViewById(R.id.residence_image);
    residenceImageLoaded = (NetworkImageView) findViewById(R.id.residence_image_loaded);
    residenceInfoLayout = (RelativeLayout) findViewById(R.id.residence_info_layout);
    if (editDriver.getResidenceNumber() != null) {
        setIndicator(context, residenceIndicator, true);
        residenceValueNumber.setText(editDriver.getResidenceNumber());
        residenceValueLegalName.setText(editDriver.getLegalName());
        if (editDriver.getResidenceImage() != null)
            residenceImageLoaded.setImageUrl(editDriver.getResidenceImage(),
                    DataHolder.getInstance().getImageLoader());
    }
    if (photo2 != null)
        residenceImage.setImageBitmap(photo2);
    residenceInfoLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent scanIdIntent = new Intent(context, CameraVisionActivity.class);
            scanIdIntent.putExtra(SOURCE, REQUEST_RESIDENCE_ID);
            startActivity(scanIdIntent);
        }
    });

    nationalityIndicator = (ImageView) findViewById(R.id.nationality_indicator);
    nationalityValue = (TextView) findViewById(R.id.nationality_value);
    nationalityLayout = (RelativeLayout) findViewById(R.id.nationality_layout);
    nationalityProgressLayout = (LinearLayout) findViewById(R.id.nationality_progress_layout);
    final RelativeLayout nationalitySelector = (RelativeLayout) findViewById(R.id.nationality_selector);
    selectorsLayouts.add(nationalitySelector);
    nationalitySelectorContent = (LinearLayout) findViewById(R.id.nationality_selector_content);
    countryTask = new CountryTask(countryListHandler, "en");
    countryTask.getCountryList.execute("en");
    if (editDriver.getNationality() != null) {
        setIndicator(context, nationalityIndicator, true);
        nationalityValue.setText(editDriver.getNationality().getCountryName());
    }
    nationalityAuto = (InstantAutoComplete) findViewById(R.id.nationality_auto);
    nationalityLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            hideKeyboard(context);
            if (nationalitySelector.getVisibility() == View.GONE) {
                closeInactiveLayouts(appBarLayout, selectorsLayouts, nationalitySelector);
                mainScrollView.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mainScrollView.smoothScrollTo(0, nationalityLayout.getTop());
                        nationalityAuto.showDropDown();
                    }
                }, 1000);
            }
            if (countryTask.getCountryList.getStatus().equals(AsyncTask.Status.RUNNING)) {
                nationalityProgressLayout.setVisibility(View.VISIBLE);
                nationalitySelectorContent.setVisibility(View.GONE);
            }
            LinearLayout okayButton = (LinearLayout) findViewById(R.id.nationality_okay_button);
            okayButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (editDriver.getNationality() != null) {
                        setIndicator(context, nationalityIndicator, true);
                        nationalityValue.setText(editDriver.getNationality().getCountryName());
                        addressLayout.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                addressLayout.performClick();
                            }
                        }, 1000);
                    } else {
                        setIndicator(context, nationalityIndicator, false);
                        nationalitySelector.setVisibility(View.GONE);
                    }
                }
            });
            LinearLayout cancelButton = (LinearLayout) findViewById(R.id.nationality_cancel_button);
            cancelButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    nationalitySelector.setVisibility(View.GONE);
                }
            });
        }
    });

    addressIndicator = (ImageView) findViewById(R.id.preferred_address_indicator);
    addressValue = (TextView) findViewById(R.id.preferred_address_value);
    addressLayout = (RelativeLayout) findViewById(R.id.preferred_address_layout);
    if (editDriver.getPreferredAddress() != null) {
        setIndicator(context, addressIndicator, true);
        preferredPlace.setAddress(transform(editDriver.getPreferredAddress()));
        preferredPlace.setLocation(transform(editDriver.getPreferredLocation()));
        addressValue.setText(preferredPlace.getAddress().getFullAddress());
    }
    addressChooser = (FrameLayout) findViewById(R.id.preferred_address_chooser);
    selectorsLayouts.add(addressChooser);
    addressLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            hideKeyboard(context);
            try {
                if (addressChooser.getVisibility() == View.GONE) {
                    closeInactiveLayouts(appBarLayout, selectorsLayouts, addressChooser);
                    getSupportFragmentManager().beginTransaction()
                            .replace(R.id.preferred_address_chooser,
                                    PlaceChooserFragment.newInstance(preferredPlace, placeChooseHandler))
                            .commit();
                    mainScrollView.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            mainScrollView.smoothScrollTo(0, addressLayout.getTop());
                        }
                    }, 1500);
                } else {
                    addressChooser.setVisibility(View.GONE);
                    getSupportFragmentManager().popBackStack();
                }
            } catch (Resources.NotFoundException | OutOfMemoryError ignored) {
            }
        }
    });

    final ImageView phoneIndicator = (ImageView) findViewById(R.id.driver_phone_indicator);
    final TextView phoneValue = (TextView) findViewById(R.id.driver_phone_value);
    if (editDriver.getPhoneNumber() != null) {
        setIndicator(context, phoneIndicator, true);
        phoneValue.setText(editDriver.getPhoneNumber().replace(currentCountry.getPhoneCode(), ""));
    }
    final LinearLayout phoneSelector = (LinearLayout) findViewById(R.id.driver_phone_selector);
    selectorsLayouts.add(phoneSelector);
    phoneLayout = (RelativeLayout) findViewById(R.id.driver_phone_layout);
    phoneLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            hideKeyboard(context);
            if (phoneSelector.getVisibility() == View.GONE) {
                closeInactiveLayouts(appBarLayout, selectorsLayouts, phoneSelector);
                mainScrollView.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mainScrollView.smoothScrollTo(0, phoneLayout.getTop());
                    }
                }, 1000);
            }
            final EditText input = (EditText) findViewById(R.id.phone_number);
            if (editDriver.getPhoneNumber() != null)
                input.setText(editDriver.getPhoneNumber().replace(currentCountry.getPhoneCode(), ""));
            TextView phoneCode = (TextView) findViewById(R.id.country_code);
            phoneCode.setText(currentCountry.getPhoneCode());
            NetworkImageView countryFlag = (NetworkImageView) findViewById(R.id.country_flag);
            countryFlag.setImageUrl(currentCountry.getFlag(), DataHolder.getInstance().getImageLoader());
            LinearLayout okayButton = (LinearLayout) findViewById(R.id.driver_phone_okay_button);
            okayButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    if (!input.getText().toString().isEmpty()) {
                        String phoneNumberEdit = currentCountry.getPhoneCode()
                                + input.getText().toString().replaceAll(" ", "");
                        editDriver.setPhoneNumber(phoneNumberEdit);
                        phoneValue.setText(phoneNumberEdit);
                        setIndicator(context, phoneIndicator, true);
                        mainScrollView.postDelayed(new Runnable() {
                            @Override
                            public void run() {
                                mainScrollView.smoothScrollTo(0, dobLayout.getTop());
                            }
                        }, 1000);
                    } else {
                        phoneValue.setText(getString(R.string.driver_phone_hint));
                        setIndicator(context, phoneIndicator, false);
                    }
                    phoneSelector.setVisibility(View.GONE);
                }
            });
            LinearLayout cancelButton = (LinearLayout) findViewById(R.id.driver_phone_cancel_button);
            cancelButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    phoneSelector.setVisibility(View.GONE);
                }
            });
        }
    });

    dobValue = (TextView) findViewById(R.id.driver_dob_value);
    if (editDriver.getDob() != null)
        dobValue.setText(StringManipulation.getFormattedDate(editDriver.getDob()));
    dobLayout = (RelativeLayout) findViewById(R.id.driver_dob_layout);
    dobLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final Calendar calendar = Calendar.getInstance();
            if (editDriver.getDob() != null) {
                dobValue.setText(StringManipulation.getFormattedDate(editDriver.getDob()));
                calendar.setTimeInMillis(editDriver.getDob());
            }
            DatePickerDialog datePickerDialog = DatePickerDialog
                    .newInstance(new DatePickerDialog.OnDateSetListener() {
                        @Override
                        public void onDateSet(DatePickerDialog view, int year, int monthOfYear,
                                int dayOfMonth) {
                            calendar.set(Calendar.YEAR, year);
                            calendar.set(Calendar.MONTH, monthOfYear);
                            calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
                            editDriver.setDob(calendar.getTimeInMillis());
                            dobValue.setText(StringManipulation.getFormattedDate(editDriver.getDob()));
                        }
                    }, calendar.get(Calendar.YEAR), calendar.get(Calendar.MONTH),
                            calendar.get(Calendar.DAY_OF_MONTH));
            datePickerDialog.show(getFragmentManager(), "Datepickerdialog");
        }
    });

    final TextView genderValue = (TextView) findViewById(R.id.driver_gender_value);
    if (editDriver.getGender() != null)
        genderValue.setText(
                editDriver.getGender() ? getString(R.string.male_option) : getString(R.string.female_option));
    final LinearLayout genderSelector = (LinearLayout) findViewById(R.id.driver_gender_selector);
    selectorsLayouts.add(genderSelector);
    final RelativeLayout genderLayout = (RelativeLayout) findViewById(R.id.driver_gender_layout);
    genderLayout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            hideKeyboard(context);
            if (genderSelector.getVisibility() == View.GONE) {
                closeInactiveLayouts(appBarLayout, selectorsLayouts, genderSelector);
                mainScrollView.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        mainScrollView.smoothScrollTo(0, genderLayout.getTop());
                    }
                }, 1000);
            } else
                genderSelector.setVisibility(View.GONE);
            final int checkedPos = editDriver.getGender() == null ? -1
                    : (editDriver.getGender() ? R.id.driver_gender_male : R.id.driver_gender_female);
            final RadioGroup insuranceRadioGroup = (RadioGroup) findViewById(R.id.driver_gender_radio_group);
            if (checkedPos != -1)
                insuranceRadioGroup.check(checkedPos);
            LinearLayout okayButton = (LinearLayout) findViewById(R.id.driver_gender_okay_button);
            okayButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    switch (insuranceRadioGroup.getCheckedRadioButtonId()) {
                    case R.id.driver_gender_male:
                        editDriver.setGender(true);
                        genderValue.setText(getString(R.string.male_option));
                        break;
                    case R.id.driver_gender_female:
                        editDriver.setGender(false);
                        genderValue.setText(getString(R.string.female_option));
                        break;
                    default:
                        break;
                    }
                    mainScrollView.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            mainScrollView.smoothScrollTo(0, 0);
                        }
                    }, 500);
                    appBarLayout.postDelayed(new Runnable() {
                        @Override
                        public void run() {
                            appBarLayout.setExpanded(true, true);
                        }
                    }, 1500);
                }
            });
            LinearLayout cancelButton = (LinearLayout) findViewById(R.id.driver_gender_cancel_button);
            cancelButton.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    genderSelector.setVisibility(View.GONE);
                }
            });
        }
    });

    //TODO image analyis on IDs (license) and cross check with profile photo1, or maybe selfie

    uploadCount = new AtomicInteger(0);
    saveDriverAction = (FloatingActionButton) findViewById(R.id.fab_save_id);
    saveDriverAction.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            boolean error = false;
            hideKeyboard(context);
            if (editDriver.getVehicles().size() == 1) {
                setIndicator(context, vehicleIndicator, false);
                error = true;
            }
            if (licenseImage.getDrawable() == null || editDriver.getLicenseExpiry() == null
                    || editDriver.getLicenseNumber() == null) {
                setIndicator(context, licenseIndicator, false);
                error = true;
            }
            if (residenceImage.getDrawable() == null || editDriver.getResidenceNumber() == null) {
                setIndicator(context, residenceIndicator, false);
                error = true;
            }
            if (editDriver.getNationality() == null) {
                setIndicator(context, nationalityIndicator, false);
                error = true;
            }
            if (editDriver.getPreferredAddress() == null) {
                setIndicator(context, addressIndicator, false);
                error = true;
            }
            if (editDriver.getPhoneNumber() == null || editDriver.getPhoneNumber().isEmpty()) {
                setIndicator(context, phoneIndicator, false);
                error = true;
            }
            if (user == null && !registerEmailHeaderFragment.setCustomerValues())
                error = true;
            if (error)
                Snackbar.make(view, getString(R.string.incorrect_driver_data_message), Snackbar.LENGTH_LONG)
                        .show();
            else if (user != null) {
                signUpAnalytics(user.getProviderId());
                editDriver.getVehicles().remove(editDriver.getVehicles().size() - 1);
                uploadImage("driver_license_snapshot",
                        "image_" + editDriver.getPhoneNumber().replace(currentCountry.getPhoneCode(), "") + "_"
                                + editDriver.getLicenseNumber() + ".jpg",
                        ((BitmapDrawable) licenseImage.getDrawable()).getBitmap(), REQUEST_DRIVER_LICENSE);
                uploadImage("driver_residence_snapshot",
                        "image_" + editDriver.getPhoneNumber().replace(currentCountry.getPhoneCode(), "") + "_"
                                + editDriver.getResidenceNumber() + ".jpg",
                        ((BitmapDrawable) residenceImage.getDrawable()).getBitmap(), REQUEST_RESIDENCE_ID);
                crossFade(context, findViewById(R.id.driver_progress_layout),
                        findViewById(R.id.driver_main_layout), null);
                //TODO verify registration details for duplicate, correctness, etc
            }
        }
    });

    imageUploadStatus = (TextSwitcher) findViewById(R.id.image_upload_status);
    imageUploadStatus.setFactory(new ViewSwitcher.ViewFactory() {
        @Override
        public View makeView() {
            TextView switcherTextView = new TextView(getApplicationContext());
            switcherTextView.setTextSize(16);
            switcherTextView.setTypeface(null, Typeface.BOLD);
            switcherTextView.setText(getString(R.string.uploading_images));
            switcherTextView.setTextColor(getResources().getColor(R.color.colorAccent));
            return switcherTextView;
        }
    });
    Animation animationOut = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right);
    Animation animationIn = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);
    imageUploadStatus.setOutAnimation(animationOut);
    imageUploadStatus.setInAnimation(animationIn);
}

From source file:com.money.manager.ex.home.MainActivity.java

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

    MoneyManagerApplication.getApp().iocComponent.inject(this);

    if (showPrerequisite()) {
        finish();/* w  w  w.ja  va2  s .  c  om*/
        return;
    }

    // todo: remove this after the users upgrade the recent files list.
    migrateRecentDatabases();

    // Reset the request for restart. If we are in onCreate, we are restarting already.
    setRestartActivity(false);

    // Layout
    setContentView(R.layout.main_activity);

    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    if (toolbar != null)
        setSupportActionBar(toolbar);

    LinearLayout fragmentDetail = (LinearLayout) findViewById(R.id.fragmentDetail);
    setDualPanel(fragmentDetail != null && fragmentDetail.getVisibility() == View.VISIBLE);

    // Initialize current device orientation.
    if (deviceOrientation == Constants.NOT_SET) {
        deviceOrientation = getResources().getConfiguration().orientation;
    }

    // Intent. Opening from the notification or the file system.
    handleIntent();

    // Restore state. Check authentication, etc.
    if (savedInstanceState != null) {
        restoreInstanceState(savedInstanceState);
    }

    handleDeviceRotation();

    // Close any existing notifications.
    ((NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE))
            .cancel(SyncConstants.NOTIFICATION_SYNC_OPEN_FILE);

    showCurrentDatabasePath(this);

    // Read something from the database at this stage so that the db file gets created.
    InfoService infoService = new InfoService(getApplicationContext());
    String username = infoService.getInfoValue(InfoKeys.USERNAME);

    // fragments
    initHomeFragment();

    // start notification for recurring transaction
    if (!isRecurringTransactionStarted) {
        AppSettings settings = new AppSettings(this);
        boolean showNotification = settings.getBehaviourSettings().getNotificationRecurringTransaction();
        if (showNotification) {
            RecurringTransactionNotifications notifications = new RecurringTransactionNotifications(this);
            notifications.notifyRepeatingTransaction();
            isRecurringTransactionStarted = true;
        }
    }

    // notification send broadcast
    Intent serviceRepeatingTransaction = new Intent(getApplicationContext(),
            RecurringTransactionBootReceiver.class);
    getApplicationContext().sendBroadcast(serviceRepeatingTransaction);

    initializeDrawer();

    initializeSync();
}

From source file:com.cypress.cysmart.BLEServiceFragments.SensorHubService.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    final View rootView = inflater.inflate(R.layout.sensor_hub, container, false);
    LinearLayout parent = (LinearLayout) rootView.findViewById(R.id.parent_sensorhub);
    parent.setOnClickListener(new OnClickListener() {

        @Override/* w  w  w  . ja v  a 2s  .c  o  m*/
        public void onClick(View v) {

        }
    });
    accX = (TextView) rootView.findViewById(R.id.acc_x_value);
    accY = (TextView) rootView.findViewById(R.id.acc_y_value);
    accZ = (TextView) rootView.findViewById(R.id.acc_z_value);
    BAT = (TextView) rootView.findViewById(R.id.bat_value);
    STEMP = (TextView) rootView.findViewById(R.id.temp_value);
    mProgressDialog = new ProgressDialog(getActivity());
    Spressure = (TextView) rootView.findViewById(R.id.pressure_value);

    // Locate device button listener
    Button locateDevice = (Button) rootView.findViewById(R.id.locate_device);
    locateDevice.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            Button btn = (Button) v;
            String buttonText = btn.getText().toString();
            String startText = getResources().getString(R.string.sen_hub_locate);
            String stopText = getResources().getString(R.string.sen_hub_locate_stop);
            if (buttonText.equalsIgnoreCase(startText)) {
                btn.setText(stopText);
                if (mWriteAlertCharacteristic != null) {
                    byte[] convertedBytes = convertingTobyteArray(IMM_HIGH_ALERT);
                    BluetoothLeService.writeCharacteristicNoresponse(mWriteAlertCharacteristic, convertedBytes);
                }

            } else {
                btn.setText(startText);
                if (mWriteAlertCharacteristic != null) {
                    byte[] convertedBytes = convertingTobyteArray(IMM_NO_ALERT);
                    BluetoothLeService.writeCharacteristicNoresponse(mWriteAlertCharacteristic, convertedBytes);
                }
            }

        }
    });
    final ImageButton acc_more = (ImageButton) rootView.findViewById(R.id.acc_more);
    final ImageButton stemp_more = (ImageButton) rootView.findViewById(R.id.stemp_more);
    final ImageButton spressure_more = (ImageButton) rootView.findViewById(R.id.spressure_more);

    final LinearLayout acc_layLayout = (LinearLayout) rootView.findViewById(R.id.acc_context_menu);
    final LinearLayout stemp_layLayout = (LinearLayout) rootView.findViewById(R.id.stemp_context_menu);
    final LinearLayout spressure_layLayout = (LinearLayout) rootView.findViewById(R.id.spressure_context_menu);

    // expand listener
    acc_more.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (acc_layLayout.getVisibility() != View.VISIBLE) {
                acc_more.setRotation(90);
                CustomSlideAnimation a = new CustomSlideAnimation(acc_layLayout, CustomSlideAnimation.EXPAND);
                a.setHeight(height);
                acc_layLayout.startAnimation(a);
                acc_scan_interval = (EditText) rootView.findViewById(R.id.acc_sensor_scan_interval);
                if (ACCSensorScanCharacteristic != null) {
                    acc_scan_interval.setText(ACCSensorScanCharacteristic);
                }
                acc_sensortype = (TextView) rootView.findViewById(R.id.acc_sensor_type);
                if (ACCSensorTypeCharacteristic != null) {
                    acc_sensortype.setText(ACCSensorTypeCharacteristic);
                }
                acc_scan_interval.setOnEditorActionListener(new OnEditorActionListener() {

                    @Override
                    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                        if (actionId == EditorInfo.IME_ACTION_DONE) {
                            int myNum = 0;

                            try {
                                myNum = Integer.parseInt(acc_scan_interval.getText().toString());
                            } catch (NumberFormatException nfe) {
                                nfe.printStackTrace();
                            }
                            byte[] convertedBytes = convertingTobyteArray(Integer.toString(myNum));
                            BluetoothLeService.writeCharacteristicNoresponse(mReadACCSensorScanCharacteristic,
                                    convertedBytes);
                        }
                        return false;
                    }
                });
                Spinner spinner_filterconfiguration = (Spinner) rootView
                        .findViewById(R.id.acc_filter_configuration);
                // Create an ArrayAdapter using the string array and a
                // default
                // spinner layout
                ArrayAdapter<CharSequence> adapter_filterconfiguration = ArrayAdapter.createFromResource(
                        getActivity(), R.array.filter_configuration_alert_array,
                        android.R.layout.simple_spinner_item);
                // Specify the layout to use when the list of choices
                // appears
                adapter_filterconfiguration
                        .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                // Apply the adapter to the spinner
                spinner_filterconfiguration.setAdapter(adapter_filterconfiguration);

            } else {
                acc_more.setRotation(-90);

                acc_scan_interval.setText("");
                acc_sensortype.setText("");
                CustomSlideAnimation a = new CustomSlideAnimation(acc_layLayout, CustomSlideAnimation.COLLAPSE);
                height = a.getHeight();
                acc_layLayout.startAnimation(a);
            }
        }
    });
    // expand listener
    stemp_more.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {

            if (stemp_layLayout.getVisibility() != View.VISIBLE) {
                stemp_more.setRotation(90);
                CustomSlideAnimation a = new CustomSlideAnimation(stemp_layLayout, CustomSlideAnimation.EXPAND);
                a.setHeight(height);
                stemp_layLayout.startAnimation(a);
                stemp_scan_interval = (EditText) rootView.findViewById(R.id.stemp_sensor_scan_interval);
                if (STEMPSensorScanCharacteristic != null) {
                    stemp_scan_interval.setText(STEMPSensorScanCharacteristic);
                }
                stemp_sensortype = (TextView) rootView.findViewById(R.id.stemp_sensor_type);
                if (STEMPSensorTypeCharacteristic != null) {
                    stemp_sensortype.setText(STEMPSensorTypeCharacteristic);
                }
                stemp_scan_interval.setOnEditorActionListener(new OnEditorActionListener() {

                    @Override
                    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                        if (actionId == EditorInfo.IME_ACTION_DONE) {
                            int myNum = 0;

                            try {
                                myNum = Integer.parseInt(stemp_scan_interval.getText().toString());
                            } catch (NumberFormatException nfe) {
                                nfe.printStackTrace();
                            }
                            byte[] convertedBytes = convertingTobyteArray(Integer.toString(myNum));
                            BluetoothLeService.writeCharacteristicNoresponse(mReadSTEMPSensorScanCharacteristic,
                                    convertedBytes);
                        }
                        return false;
                    }
                });

            } else {
                stemp_more.setRotation(-90);
                stemp_scan_interval.setText("");
                stemp_sensortype.setText("");
                CustomSlideAnimation a = new CustomSlideAnimation(stemp_layLayout,
                        CustomSlideAnimation.COLLAPSE);
                height = a.getHeight();
                stemp_layLayout.startAnimation(a);
            }
        }
    });
    // expand listener
    spressure_more.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (spressure_layLayout.getVisibility() != View.VISIBLE) {
                spressure_more.setRotation(90);
                CustomSlideAnimation a = new CustomSlideAnimation(spressure_layLayout,
                        CustomSlideAnimation.EXPAND);
                a.setHeight(height);
                spressure_layLayout.startAnimation(a);
                spressure_scan_interval = (EditText) rootView.findViewById(R.id.spressure_sensor_scan_interval);
                if (SPRESSURESensorScanCharacteristic != null) {
                    spressure_scan_interval.setText(SPRESSURESensorScanCharacteristic);
                }
                spressure_sensortype = (TextView) rootView.findViewById(R.id.spressure_sensor_type);
                if (SPRESSURESensorTypeCharacteristic != null) {
                    spressure_sensortype.setText(SPRESSURESensorTypeCharacteristic);
                }
                spressure_scan_interval.setOnEditorActionListener(new OnEditorActionListener() {

                    @Override
                    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                        if (actionId == EditorInfo.IME_ACTION_DONE) {
                            int myNum = 0;

                            try {
                                myNum = Integer.parseInt(stemp_scan_interval.getText().toString());
                            } catch (NumberFormatException nfe) {
                                nfe.printStackTrace();
                            }
                            byte[] convertedBytes = convertingTobyteArray(Integer.toString(myNum));
                            BluetoothLeService.writeCharacteristicNoresponse(
                                    mReadSPRESSURESensorScanCharacteristic, convertedBytes);
                        }
                        return false;
                    }
                });
                Spinner spinner_filterconfiguration = (Spinner) rootView
                        .findViewById(R.id.spressure_filter_configuration);
                // Create an ArrayAdapter using the string array and a
                // default
                // spinner layout
                ArrayAdapter<CharSequence> adapter_filterconfiguration = ArrayAdapter.createFromResource(
                        getActivity(), R.array.filter_configuration_alert_array,
                        android.R.layout.simple_spinner_item);
                // Specify the layout to use when the list of choices
                // appears
                adapter_filterconfiguration
                        .setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
                // Apply the adapter to the spinner
                spinner_filterconfiguration.setAdapter(adapter_filterconfiguration);
                spressure_threshold_value = (EditText) rootView.findViewById(R.id.spressure_threshold);
                spressure_threshold_value.setOnEditorActionListener(new OnEditorActionListener() {

                    @Override
                    public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
                        if (actionId == EditorInfo.IME_ACTION_DONE) {
                            int myNum = 0;

                            try {
                                myNum = Integer.parseInt(spressure_threshold_value.getText().toString());
                            } catch (NumberFormatException nfe) {
                                nfe.printStackTrace();
                            }
                            byte[] convertedBytes = convertingTobyteArray(Integer.toString(myNum));
                            BluetoothLeService.writeCharacteristicNoresponse(
                                    mReadSPRESSUREThresholdCharacteristic, convertedBytes);
                        }
                        return false;
                    }
                });

            } else {
                spressure_more.setRotation(-90);
                spressure_scan_interval.setText("");
                spressure_sensortype.setText("");
                spressure_threshold_value.setText("");
                CustomSlideAnimation a = new CustomSlideAnimation(spressure_layLayout,
                        CustomSlideAnimation.COLLAPSE);
                height = a.getHeight();
                spressure_layLayout.startAnimation(a);
            }

        }
    });
    ImageButton acc_graph = (ImageButton) rootView.findViewById(R.id.acc_graph);
    setupAccChart(rootView);

    acc_graph.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mACCGraphLayoutParent.getVisibility() != View.VISIBLE) {
                mACCGraphLayoutParent.setVisibility(View.VISIBLE);

            } else {
                mACCGraphLayoutParent.setVisibility(View.GONE);
            }

        }
    });
    ImageButton stemp_graph = (ImageButton) rootView.findViewById(R.id.temp_graph);
    setupTempGraph(rootView);
    stemp_graph.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mTemperatureGraphLayoutParent.getVisibility() != View.VISIBLE) {
                mTemperatureGraphLayoutParent.setVisibility(View.VISIBLE);
            } else {
                mTemperatureGraphLayoutParent.setVisibility(View.GONE);
            }

        }
    });
    ImageButton spressure_graph = (ImageButton) rootView.findViewById(R.id.pressure_graph);
    setupPressureGraph(rootView);

    spressure_graph.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View v) {
            if (mPressureGraphLayoutParent.getVisibility() != View.VISIBLE) {
                mPressureGraphLayoutParent.setVisibility(View.VISIBLE);

            } else {

                mPressureGraphLayoutParent.setVisibility(View.GONE);
            }

        }
    });
    setHasOptionsMenu(true);
    return rootView;
}

From source file:org.linphone.InCallActivity.java

private void displayCall(Resources resources, LinphoneCall call, int index) {
    String sipUri = call.getRemoteAddress().asStringUriOnly();
    LinphoneAddress lAddress;/* w  ww.ja v  a  2s  .c  om*/
    try {
        lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri);
    } catch (LinphoneCoreException e) {
        Log.e("Incall activity cannot parse remote address", e);
        lAddress = LinphoneCoreFactory.instance().createLinphoneAddress("uknown", "unknown", "unkonown");
    }

    // Control Row
    LinearLayout callView = (LinearLayout) inflater.inflate(R.layout.active_call_control_row, container, false);
    callView.setId(index + 1);
    setContactName(callView, lAddress, sipUri, resources);
    displayCallStatusIconAndReturnCallPaused(callView, call);
    setRowBackground(callView, index);
    registerCallDurationTimer(callView, call);
    callsList.addView(callView);

    // Image Row
    LinearLayout imageView = (LinearLayout) inflater.inflate(R.layout.active_call_image_row, container, false);
    Contact contact = ContactsManager.getInstance()
            .findContactWithAddress(imageView.getContext().getContentResolver(), lAddress);
    if (contact != null) {
        displayOrHideContactPicture(imageView, contact.getPhotoUri(), contact.getThumbnailUri(), false);
    } else {
        displayOrHideContactPicture(imageView, null, null, false);
    }
    callsList.addView(imageView);

    callView.setTag(imageView);
    callView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (v.getTag() != null) {
                View imageView = (View) v.getTag();
                if (imageView.getVisibility() == View.VISIBLE)
                    imageView.setVisibility(View.GONE);
                else
                    imageView.setVisibility(View.VISIBLE);
                callsList.invalidate();
            }
        }
    });
}

From source file:com.synox.android.ui.activity.FileActivity.java

/**
 * Retrieves user quota if available/*from  w w w .java 2  s  . c  o m*/
 *
 * @param navigationDrawerLayout
 */
private void getUserQuota(final NavigationView navigationDrawerLayout, final String user) {
    // set user space information
    Thread t = new Thread(new Runnable() {
        public void run() {

            try {
                OwnCloudAccount ocAccount = new OwnCloudAccount(mAccount, MainApp.getAppContext());

                OwnCloudClient client = OwnCloudClientManagerFactory.getDefaultSingleton()
                        .getClientFor(ocAccount, MainApp.getAppContext());
                GetMethod get = null;

                final ProgressBar quotaProgress = (ProgressBar) navigationDrawerLayout
                        .findViewById(R.id.usage_progress);
                final LinearLayout quotaInformation = (LinearLayout) navigationDrawerLayout
                        .findViewById(R.id.quotaInformation);

                try {
                    get = new GetMethod(
                            client.getBaseUri() + "/ocs/v1.php/cloud/users/" + user + "?format=json");
                    int status = client.executeMethod(get);
                    if (status == HttpStatus.SC_OK) {
                        JSONObject json = new JSONObject(get.getResponseBodyAsString());
                        JSONObject ocs = json.getJSONObject("ocs");
                        JSONObject meta = ocs.getJSONObject("meta");
                        JSONObject data = ocs.getJSONObject("data");
                        JSONObject quota = data.getJSONObject("quota");
                        if (meta.getString("statuscode").equals("100")) {

                            try {
                                final long used = Long.parseLong(quota.getString("used"));
                                final long total = Long.parseLong(quota.getString("total"));
                                final int relative = (int) Math.ceil(quota.getDouble("relative"));

                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        if (quotaProgress != null) {

                                            if (quotaInformation.getVisibility() == View.INVISIBLE) {
                                                Animation animation = AnimationUtils.loadAnimation(
                                                        navigationDrawerLayout.getContext(),
                                                        R.anim.abc_slide_in_bottom);
                                                quotaInformation.setAnimation(animation);
                                            }
                                            quotaInformation.setVisibility(View.VISIBLE);
                                            quotaProgress.setProgress(relative);
                                        } else {
                                            quotaInformation.setVisibility(View.INVISIBLE);
                                        }

                                        TextView usageText = (TextView) navigationDrawerLayout
                                                .findViewById(R.id.usage_text);
                                        usageText.setText(String.format(getString(R.string.usage_text),
                                                DisplayUtils.bytesToHumanReadable(used),
                                                DisplayUtils.bytesToHumanReadable(total)));

                                    }
                                });

                            } catch (NumberFormatException nfe) {
                                Log_OC.e(this.getClass().getName(),
                                        "Error retrieving quota usage from server.");
                            }
                        }
                    } else {
                        client.exhaustResponse(get.getResponseBodyAsStream());
                    }
                } catch (final Exception e) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            quotaInformation.setVisibility(View.INVISIBLE);
                            e.printStackTrace();
                        }
                    });
                } finally

                {
                    if (get != null) {
                        get.releaseConnection();
                    }
                }

            } catch (com.synox.android.lib.common.accounts.AccountUtils.AccountNotFoundException e) {
                Log_OC.e(this.getClass().getName(), e.getMessage());
            } catch (AuthenticatorException | OperationCanceledException | IOException e) {
                Log_OC.e(this.getClass().getName(), e.getMessage());
            }
        }
    });
    t.start();
}

From source file:org.xingjitong.InCallActivity.java

private void displayCall(Resources resources, LinphoneCall call, int index) {
    String sipUri = call.getRemoteAddress().asStringUriOnly();
    LinphoneAddress lAddress = LinphoneCoreFactory.instance().createLinphoneAddress(sipUri);
    // Control Row
    LinearLayout callView = (LinearLayout) inflater.inflate(R.layout.active_call_control_row, container, false);
    setContactPhone(callView, lAddress, sipUri, resources);
    //yyppcallingfun del
    //displayCallStatusIconAndReturnCallPaused(callView, call);
    setRowBackground(callView, index);//  www.  j a v a  2s.co m
    registerCallDurationTimer(callView, call);
    callsList.addView(callView);

    // Image Row
    LinearLayout imageView = (LinearLayout) inflater.inflate(R.layout.active_call_image_row, container, false);
    Uri pictureUri = LinphoneUtils.findUriPictureOfContactAndSetDisplayName(lAddress,
            imageView.getContext().getContentResolver());

    final TextView name = (TextView) imageView.findViewById(R.id.call_name);
    //yyppcalling //yyppcallingui add
    //callhint = (TextView) imageView.findViewById(R.id.incall_callhint);

    phone = sipUri.substring(sipUri.indexOf(":") + 1, sipUri.indexOf("@"));
    if (phone.startsWith("01") && !phone.startsWith("010")) {
        phone = phone.substring(1);
    } else if (phone.startsWith("51201")) {
        phone = phone.substring(4);
    } else if (phone.startsWith("512")) {
        phone = phone.substring(3);
    }
    if (!phone.startsWith("1") && !phone.startsWith("0")) {
        phone = "0" + phone;
    }
    handler.post(new Runnable() {

        @Override
        public void run() {
            String n = ContactDB.Instance().getName(phone);
            if (!n.equals(phone) && n != null) {
                name.invalidate();
                name.setText(n);
            }
        }
    });
    displayOrHideContactPicture(imageView, pictureUri, false);
    callsList.addView(imageView);

    callView.setTag(imageView);
    callView.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (v.getTag() != null) {
                View imageView = (View) v.getTag();
                if (imageView.getVisibility() == View.VISIBLE)
                    imageView.setVisibility(View.GONE);
                else
                    imageView.setVisibility(View.VISIBLE);
                callsList.invalidate();
            }
        }
    });
}

From source file:com.samknows.measurement.activity.SamKnowsAggregateStatViewerActivity.java

@Override
public void onClick(View v) {
    // Toast.makeText(this,"clicked ..."+v.getId(),3000).show();

    ImageView button = null;/*from   w  ww.  j  a v  a 2 s.c o m*/
    LinearLayout l = null;

    int grid = 0;
    int testid = 0;
    boolean buttonfound = false;

    int id = v.getId();
    if (id == R.id.download_header || id == R.id.btn_download_toggle) {
        if (total_download_archive_records > 0) {
            buttonfound = true;
        }
        grid = R.id.agggregate_test1_grid;
        testid = TestResult.DOWNLOAD_TEST_ID;
        l = (LinearLayout) findViewById(R.id.download_content);
        button = (ImageView) findViewById(R.id.btn_download_toggle);

    }

    if (id == R.id.upload_header || id == R.id.btn_upload_toggle) {

        if (total_upload_archive_records > 0) {
            buttonfound = true;
        }
        grid = R.id.agggregate_test2_grid;
        testid = TestResult.UPLOAD_TEST_ID;
        l = (LinearLayout) findViewById(R.id.upload_content);
        button = (ImageView) findViewById(R.id.btn_upload_toggle);
    }

    if (id == R.id.latency_header || id == R.id.btn_latency_toggle) {
        if (total_latency_archive_records > 0) {
            buttonfound = true;
        }
        grid = R.id.agggregate_test3_grid;
        testid = TestResult.LATENCY_TEST_ID;
        l = (LinearLayout) findViewById(R.id.latency_content);
        button = (ImageView) findViewById(R.id.btn_latency_toggle);
    }

    if (id == R.id.packetloss_header || id == R.id.btn_packetloss_toggle) {
        if (total_packetloss_archive_records > 0) {
            buttonfound = true;
        }
        grid = R.id.agggregate_test4_grid;
        testid = TestResult.PACKETLOSS_TEST_ID;
        l = (LinearLayout) findViewById(R.id.packetloss_content);
        button = (ImageView) findViewById(R.id.btn_packetloss_toggle);
    }

    if (id == R.id.jitter_header || id == R.id.btn_jitter_toggle) {
        if (total_jitter_archive_records > 0) {
            buttonfound = true;
        }
        grid = R.id.agggregate_test5_grid;
        testid = TestResult.JITTER_TEST_ID;
        l = (LinearLayout) findViewById(R.id.jitter_content);
        button = (ImageView) findViewById(R.id.btn_jitter_toggle);
    }

    // actions

    if (buttonfound) {

        if (l.getVisibility() == View.INVISIBLE) {

            button.setBackgroundResource(R.drawable.btn_up);
            button.setContentDescription(getString(R.string.close_panel));
            // graphHandler1.update();
            l.measure(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
            target_height = l.getMeasuredHeight();

            clearGrid(grid);
            loadDownloadGrid(testid, grid, 0, 5);

            l.getLayoutParams().height = 0;
            l.setVisibility(View.VISIBLE);

            ResizeAnimation animation = null;

            animation = new ResizeAnimation(l, target_height, 0, false);
            animation.setDuration(500);
            animation.setFillEnabled(true);
            animation.setFillAfter(true);

            animation.setAnimationListener(new Animation.AnimationListener() {
                @Override
                public void onAnimationStart(Animation animation) {
                }

                @Override
                public void onAnimationRepeat(Animation animation) {
                }

                @Override
                public void onAnimationEnd(Animation animation) {
                }
            });
            l.startAnimation(animation);

        } else {

            ResizeAnimation animation = null;
            int required_height = l.getMeasuredHeight();
            animation = new ResizeAnimation(l, 0, target_height, false);
            animation.setDuration(500);
            animation.setFillEnabled(true);
            animation.setFillAfter(true);
            MyAnimationListener animationListener = new MyAnimationListener();
            animationListener.setView(l);
            animation.setAnimationListener(animationListener);
            l.startAnimation(animation);

            button.setBackgroundResource(R.drawable.btn_down);
            button.setContentDescription(getString(R.string.open_panel));
        }
    }

}

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

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

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

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

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

    actionBar = getActionBar();

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

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

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

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

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

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

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

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

            public void onDrawerClosed(View view) {

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

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

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

                    logoutVisible = false;
                }

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

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

                invalidateOptionsMenu();
            }

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

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

                invalidateOptionsMenu();
            }

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

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

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

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

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

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

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

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

                    @Override
                    public void onAnimationRepeat(Animation animation) {

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

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

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

                    @Override
                    public void onAnimationRepeat(Animation animation) {

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

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

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

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

                    @Override
                    public void onAnimationRepeat(Animation animation) {

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

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

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

                    @Override
                    public void onAnimationRepeat(Animation animation) {

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

                logoutVisible = false;
            }
        }
    });

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

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

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

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

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

            }

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

                }
            }, 400);
        }
    });

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

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

            }

            return false;
        }
    });

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

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

    drawerList.setAdapter(adapter);

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

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

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

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

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

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

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

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

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

            }

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

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

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

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

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

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

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

                                }

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

    statusBar = findViewById(R.id.activity_status_bar);

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

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

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

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

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

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

        statusBar.setVisibility(View.VISIBLE);

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

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

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

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

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

        }

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

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

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

                    notificationList.disableSwipeToDismiss();

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

                    notificationList.enableSwipeToDismiss();

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

                notificationList.setAdapter(notificationAdapter);
            }
        });

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

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

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

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

                return null;
            }
        });

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

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

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

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

    try {//from  w ww .  j ava2  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));
    }
}