Example usage for android.widget LinearLayout setOnClickListener

List of usage examples for android.widget LinearLayout setOnClickListener

Introduction

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

Prototype

public void setOnClickListener(@Nullable OnClickListener l) 

Source Link

Document

Register a callback to be invoked when this view is clicked.

Usage

From source file:com.ehret.mixit.fragment.SessionDetailFragment.java

private void addSpeakerInfo(Talk conference) {
    //On vide les lments
    sessionPersonList.removeAllViews();/*from  w ww .j  av a 2  s. co m*/

    List<Member> speakers = new ArrayList<>();
    for (Speaker member : conference.getSpeakers()) {
        Member membre = MembreFacade.getInstance().getMembre(getActivity(), TypeFile.speaker.name(),
                member.getIdMember());

        if (membre != null) {
            speakers.add(membre);
        }
    }

    //On affiche les liens que si on a recuperer des choses
    if (!speakers.isEmpty()) {
        //On utilisait auparavant une liste pour afficher ces lments dans la page mais cette liste
        //empche d'avoir un ScrollView englobant pour toute la page. Nous utilisons donc un tableau

        //On ajoute un table layout
        TableLayout.LayoutParams tableParams = new TableLayout.LayoutParams(
                TableLayout.LayoutParams.MATCH_PARENT, TableLayout.LayoutParams.WRAP_CONTENT);
        TableLayout tableLayout = new TableLayout(getActivity().getBaseContext());
        tableLayout.setLayoutParams(tableParams);

        if (mInflater != null) {
            for (final Member membre : speakers) {
                LinearLayout row = (LinearLayout) mInflater.inflate(R.layout.item_person, tableLayout, false);
                row.setBackgroundResource(R.drawable.row_transparent_background);

                //Dans lequel nous allons ajouter le contenu que nous faisons mapp dans
                TextView userName = (TextView) row.findViewById(R.id.person_user_name);
                TextView descriptif = (TextView) row.findViewById(R.id.person_shortdesciptif);
                TextView level = (TextView) row.findViewById(R.id.person_level);
                ImageView profileImage = (ImageView) row.findViewById(R.id.person_user_image);

                userName.setText(membre.getCompleteName());

                if (membre.getShortDescription() != null) {
                    descriptif.setText(membre.getShortDescription().trim());
                }

                //Recuperation de l'mage liee au profil
                Bitmap image = FileUtils.getImageProfile(getActivity(), membre);
                if (image == null) {
                    profileImage.setImageDrawable(getResources().getDrawable(R.drawable.person_image_empty));
                } else {
                    //On regarde dans les images embarquees
                    profileImage.setImageBitmap(image);
                }

                row.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View v) {
                        ((HomeActivity) getActivity()).changeCurrentFragment(PeopleDetailFragment
                                .newInstance(TypeFile.speaker.toString(), membre.getLogin(), 7),
                                TypeFile.speaker.toString());
                    }
                });

                tableLayout.addView(row);
            }
        }
        sessionPersonList.addView(tableLayout);
    }
}

From source file:edu.berkeley.boinc.StatusFragment.java

private void loadLayout(Boolean forceUpdate) {
    //load layout, if if ClientStatus can be accessed.
    //if this is not the case, the broadcast receiver will call "loadLayout" again
    try {//from   w w w .  j  a  va 2 s  . c o  m

        int currentSetupStatus = BOINCActivity.monitor.getSetupStatus();
        int currentComputingStatus = BOINCActivity.monitor.getComputingStatus();
        int currentComputingSuspendReason = BOINCActivity.monitor.getComputingSuspendReason();
        int currentNetworkSuspendReason = BOINCActivity.monitor.getNetworkSuspendReason();

        // layout only if client RPC connection is established
        // otherwise BOINCActivity does not start Tabs
        if (currentSetupStatus == ClientStatus.SETUP_STATUS_AVAILABLE) {
            // return in cases nothing has changed
            if (forceUpdate || computingStatus != currentComputingStatus
                    || currentComputingSuspendReason != computingSuspendReason
                    || currentNetworkSuspendReason != networkSuspendReason) {

                // set layout and retrieve elements
                LinearLayout statusWrapper = (LinearLayout) getView().findViewById(R.id.status_wrapper);
                LinearLayout centerWrapper = (LinearLayout) getView().findViewById(R.id.center_wrapper);
                LinearLayout restartingWrapper = (LinearLayout) getView().findViewById(R.id.restarting_wrapper);
                TextView statusHeader = (TextView) getView().findViewById(R.id.status_header);
                ImageView statusImage = (ImageView) getView().findViewById(R.id.status_image);
                TextView statusDescriptor = (TextView) getView().findViewById(R.id.status_long);

                restartingWrapper.setVisibility(View.GONE);

                // adapt to specific computing status
                switch (currentComputingStatus) {
                case ClientStatus.COMPUTING_STATUS_NEVER:
                    statusWrapper.setVisibility(View.VISIBLE);
                    statusHeader.setText(BOINCActivity.monitor.getCurrentStatusTitle());
                    statusHeader.setVisibility(View.VISIBLE);
                    statusImage.setImageResource(R.drawable.playb48);
                    statusImage.setContentDescription(BOINCActivity.monitor.getCurrentStatusTitle());
                    statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                    centerWrapper.setVisibility(View.VISIBLE);
                    centerWrapper.setOnClickListener(runModeOnClickListener);
                    break;
                case ClientStatus.COMPUTING_STATUS_SUSPENDED:
                    statusWrapper.setVisibility(View.VISIBLE);
                    statusHeader.setText(BOINCActivity.monitor.getCurrentStatusTitle());
                    statusHeader.setVisibility(View.VISIBLE);
                    statusImage.setImageResource(R.drawable.pauseb48);
                    statusImage.setContentDescription(BOINCActivity.monitor.getCurrentStatusTitle());
                    statusImage.setClickable(false);
                    centerWrapper.setVisibility(View.VISIBLE);
                    switch (currentComputingSuspendReason) {
                    case BOINCDefs.SUSPEND_REASON_BATTERIES:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        statusImage.setImageResource(R.drawable.notconnectedb48);
                        statusHeader.setVisibility(View.GONE);
                        break;
                    case BOINCDefs.SUSPEND_REASON_USER_ACTIVE:
                        Boolean suspendDueToScreenOn = false;
                        try {
                            suspendDueToScreenOn = BOINCActivity.monitor.getSuspendWhenScreenOn();
                        } catch (RemoteException e) {
                        }
                        if (suspendDueToScreenOn) {
                            statusImage.setImageResource(R.drawable.screen48b);
                            statusHeader.setVisibility(View.GONE);
                        }
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    case BOINCDefs.SUSPEND_REASON_USER_REQ:
                        // state after user stops and restarts computation
                        centerWrapper.setVisibility(View.GONE);
                        restartingWrapper.setVisibility(View.VISIBLE);
                        break;
                    case BOINCDefs.SUSPEND_REASON_TIME_OF_DAY:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    case BOINCDefs.SUSPEND_REASON_BENCHMARKS:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        statusImage.setImageResource(R.drawable.watchb48);
                        statusHeader.setVisibility(View.GONE);
                        break;
                    case BOINCDefs.SUSPEND_REASON_DISK_SIZE:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    case BOINCDefs.SUSPEND_REASON_CPU_THROTTLE:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    case BOINCDefs.SUSPEND_REASON_NO_RECENT_INPUT:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    case BOINCDefs.SUSPEND_REASON_INITIAL_DELAY:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    case BOINCDefs.SUSPEND_REASON_EXCLUSIVE_APP_RUNNING:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    case BOINCDefs.SUSPEND_REASON_CPU_USAGE:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    case BOINCDefs.SUSPEND_REASON_NETWORK_QUOTA_EXCEEDED:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    case BOINCDefs.SUSPEND_REASON_OS:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    case BOINCDefs.SUSPEND_REASON_WIFI_STATE:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    case BOINCDefs.SUSPEND_REASON_BATTERY_CHARGING:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        statusImage.setImageResource(R.drawable.batteryb48);
                        statusHeader.setVisibility(View.GONE);
                        break;
                    case BOINCDefs.SUSPEND_REASON_BATTERY_OVERHEATED:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        statusImage.setImageResource(R.drawable.batteryb48);
                        statusHeader.setVisibility(View.GONE);
                        break;
                    default:
                        statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                        break;
                    }
                    break;
                case ClientStatus.COMPUTING_STATUS_IDLE:
                    statusWrapper.setVisibility(View.VISIBLE);
                    centerWrapper.setVisibility(View.VISIBLE);
                    statusHeader.setText(BOINCActivity.monitor.getCurrentStatusTitle());
                    statusHeader.setVisibility(View.VISIBLE);
                    statusImage.setImageResource(R.drawable.pauseb48);
                    statusImage.setContentDescription(BOINCActivity.monitor.getCurrentStatusTitle());
                    statusImage.setClickable(false);
                    statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusDescription());
                    break;
                case ClientStatus.COMPUTING_STATUS_COMPUTING:
                    statusWrapper.setVisibility(View.GONE);
                    break;
                }
                //save new computing status
                computingStatus = currentComputingStatus;
                computingSuspendReason = currentComputingSuspendReason;
                networkSuspendReason = currentNetworkSuspendReason;
                setupStatus = -1; // invalidate to force update next time no project
            }
        } else if (currentSetupStatus == ClientStatus.SETUP_STATUS_NOPROJECT) {

            if (setupStatus != ClientStatus.SETUP_STATUS_NOPROJECT) {
                // set layout and retrieve elements
                LinearLayout statusWrapper = (LinearLayout) getView().findViewById(R.id.status_wrapper);
                LinearLayout centerWrapper = (LinearLayout) getView().findViewById(R.id.center_wrapper);
                LinearLayout restartingWrapper = (LinearLayout) getView().findViewById(R.id.restarting_wrapper);
                TextView statusHeader = (TextView) getView().findViewById(R.id.status_header);
                ImageView statusImage = (ImageView) getView().findViewById(R.id.status_image);
                TextView statusDescriptor = (TextView) getView().findViewById(R.id.status_long);

                statusWrapper.setVisibility(View.VISIBLE);
                restartingWrapper.setVisibility(View.GONE);
                centerWrapper.setVisibility(View.VISIBLE);
                centerWrapper.setOnClickListener(addProjectOnClickListener);
                statusImage.setImageResource(R.drawable.projectsb48);
                statusHeader.setVisibility(View.GONE);
                statusDescriptor.setText(BOINCActivity.monitor.getCurrentStatusTitle());
                setupStatus = ClientStatus.SETUP_STATUS_NOPROJECT;
                computingStatus = -1;
            }
        } else { // BOINC client is not available
            //invalid computingStatus, forces layout on next event
            setupStatus = -1;
            computingStatus = -1;
        }
    } catch (Exception e) {
    }
}

From source file:com.forum.fiend.osp.SettingsFragment.java

private void setupUserCard() {

    if (getActivity() == null) {
        return;//w  w w  .j a v a  2s. c om
    }

    LinearLayout userLayout = (LinearLayout) getActivity().findViewById(R.id.settings_user_box);

    if (application.getSession().getServer().serverUserId.contentEquals("0")) {
        userLayout.setVisibility(View.GONE);
    } else {
        ImageView ivAvatar = (ImageView) getActivity().findViewById(R.id.settings_user_avatar);
        TextView tvUsername = (TextView) getActivity().findViewById(R.id.settings_user_name);
        ImageView ivLogout = (ImageView) getActivity().findViewById(R.id.settings_user_logout);

        tvUsername.setText(application.getSession().getServer().serverUserName);

        if (application.getSession().getServer().serverAvatar.contains("http")) {
            ImageLoader.getInstance().displayImage(application.getSession().getServer().serverAvatar, ivAvatar);
        } else {
            ivAvatar.setImageResource(R.drawable.no_avatar);
        }

        ivLogout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                logOut();
            }
        });

        userLayout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                loadMyWall();
            }
        });
    }
}

From source file:com.farmerbb.taskbar.service.TaskbarService.java

@SuppressLint("RtlHardcoded")
private void drawTaskbar() {
    IconCache.getInstance(this).clearCache();

    // Initialize layout params
    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
    U.setCachedRotation(windowManager.getDefaultDisplay().getRotation());

    final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
            WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
            WindowManager.LayoutParams.TYPE_PHONE,
            WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE | WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM,
            PixelFormat.TRANSLUCENT);//from   w  ww.j  a  va 2 s . com

    // Determine where to show the taskbar on screen
    switch (U.getTaskbarPosition(this)) {
    case "bottom_left":
        layoutId = R.layout.taskbar_left;
        params.gravity = Gravity.BOTTOM | Gravity.LEFT;
        positionIsVertical = false;
        break;
    case "bottom_vertical_left":
        layoutId = R.layout.taskbar_vertical;
        params.gravity = Gravity.BOTTOM | Gravity.LEFT;
        positionIsVertical = true;
        break;
    case "bottom_right":
        layoutId = R.layout.taskbar_right;
        params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
        positionIsVertical = false;
        break;
    case "bottom_vertical_right":
        layoutId = R.layout.taskbar_vertical;
        params.gravity = Gravity.BOTTOM | Gravity.RIGHT;
        positionIsVertical = true;
        break;
    case "top_left":
        layoutId = R.layout.taskbar_left;
        params.gravity = Gravity.TOP | Gravity.LEFT;
        positionIsVertical = false;
        break;
    case "top_vertical_left":
        layoutId = R.layout.taskbar_top_vertical;
        params.gravity = Gravity.TOP | Gravity.LEFT;
        positionIsVertical = true;
        break;
    case "top_right":
        layoutId = R.layout.taskbar_right;
        params.gravity = Gravity.TOP | Gravity.RIGHT;
        positionIsVertical = false;
        break;
    case "top_vertical_right":
        layoutId = R.layout.taskbar_top_vertical;
        params.gravity = Gravity.TOP | Gravity.RIGHT;
        positionIsVertical = true;
        break;
    }

    // Initialize views
    int theme = 0;

    SharedPreferences pref = U.getSharedPreferences(this);
    switch (pref.getString("theme", "light")) {
    case "light":
        theme = R.style.AppTheme;
        break;
    case "dark":
        theme = R.style.AppTheme_Dark;
        break;
    }

    boolean altButtonConfig = pref.getBoolean("alt_button_config", false);

    ContextThemeWrapper wrapper = new ContextThemeWrapper(this, theme);
    layout = (LinearLayout) LayoutInflater.from(wrapper).inflate(layoutId, null);
    taskbar = (LinearLayout) layout.findViewById(R.id.taskbar);
    scrollView = (FrameLayout) layout.findViewById(R.id.taskbar_scrollview);

    if (altButtonConfig) {
        space = (Space) layout.findViewById(R.id.space_alt);
        layout.findViewById(R.id.space).setVisibility(View.GONE);
    } else {
        space = (Space) layout.findViewById(R.id.space);
        layout.findViewById(R.id.space_alt).setVisibility(View.GONE);
    }

    space.setOnClickListener(v -> toggleTaskbar());

    startButton = (ImageView) layout.findViewById(R.id.start_button);
    int padding;

    if (pref.getBoolean("app_drawer_icon", false)) {
        startButton.setImageDrawable(ContextCompat.getDrawable(this, R.mipmap.ic_launcher));
        padding = getResources().getDimensionPixelSize(R.dimen.app_drawer_icon_padding_alt);
    } else {
        startButton.setImageDrawable(ContextCompat.getDrawable(this, R.drawable.all_apps_button_icon));
        padding = getResources().getDimensionPixelSize(R.dimen.app_drawer_icon_padding);
    }

    startButton.setPadding(padding, padding, padding, padding);
    startButton.setOnClickListener(ocl);
    startButton.setOnLongClickListener(view -> {
        openContextMenu();
        return true;
    });

    startButton.setOnGenericMotionListener((view, motionEvent) -> {
        if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS
                && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY)
            openContextMenu();

        return false;
    });

    refreshInterval = (int) (Float.parseFloat(pref.getString("refresh_frequency", "2")) * 1000);
    if (refreshInterval == 0)
        refreshInterval = 100;

    sortOrder = pref.getString("sort_order", "false");
    runningAppsOnly = pref.getString("recents_amount", "past_day").equals("running_apps_only");

    switch (pref.getString("recents_amount", "past_day")) {
    case "past_day":
        searchInterval = System.currentTimeMillis() - AlarmManager.INTERVAL_DAY;
        break;
    case "app_start":
        long oneDayAgo = System.currentTimeMillis() - AlarmManager.INTERVAL_DAY;
        long appStartTime = pref.getLong("time_of_service_start", System.currentTimeMillis());
        long deviceStartTime = System.currentTimeMillis() - SystemClock.elapsedRealtime();
        long startTime = deviceStartTime > appStartTime ? deviceStartTime : appStartTime;

        searchInterval = startTime > oneDayAgo ? startTime : oneDayAgo;
        break;
    }

    Intent intent = new Intent("com.farmerbb.taskbar.HIDE_START_MENU");
    LocalBroadcastManager.getInstance(TaskbarService.this).sendBroadcast(intent);

    if (altButtonConfig) {
        button = (Button) layout.findViewById(R.id.hide_taskbar_button_alt);
        layout.findViewById(R.id.hide_taskbar_button).setVisibility(View.GONE);
    } else {
        button = (Button) layout.findViewById(R.id.hide_taskbar_button);
        layout.findViewById(R.id.hide_taskbar_button_alt).setVisibility(View.GONE);
    }

    try {
        button.setTypeface(Typeface.createFromFile("/system/fonts/Roboto-Regular.ttf"));
    } catch (RuntimeException e) {
        /* Gracefully fail */ }

    updateButton(false);
    button.setOnClickListener(v -> toggleTaskbar());

    LinearLayout buttonLayout = (LinearLayout) layout.findViewById(
            altButtonConfig ? R.id.hide_taskbar_button_layout_alt : R.id.hide_taskbar_button_layout);
    if (buttonLayout != null)
        buttonLayout.setOnClickListener(v -> toggleTaskbar());

    LinearLayout buttonLayoutToHide = (LinearLayout) layout.findViewById(
            altButtonConfig ? R.id.hide_taskbar_button_layout : R.id.hide_taskbar_button_layout_alt);
    if (buttonLayoutToHide != null)
        buttonLayoutToHide.setVisibility(View.GONE);

    int backgroundTint = U.getBackgroundTint(this);
    int accentColor = U.getAccentColor(this);

    dashboardButton = (FrameLayout) layout.findViewById(R.id.dashboard_button);
    navbarButtons = (LinearLayout) layout.findViewById(R.id.navbar_buttons);

    dashboardEnabled = pref.getBoolean("dashboard", false);
    if (dashboardEnabled) {
        layout.findViewById(R.id.square1).setBackgroundColor(accentColor);
        layout.findViewById(R.id.square2).setBackgroundColor(accentColor);
        layout.findViewById(R.id.square3).setBackgroundColor(accentColor);
        layout.findViewById(R.id.square4).setBackgroundColor(accentColor);
        layout.findViewById(R.id.square5).setBackgroundColor(accentColor);
        layout.findViewById(R.id.square6).setBackgroundColor(accentColor);

        dashboardButton.setOnClickListener(v -> LocalBroadcastManager.getInstance(TaskbarService.this)
                .sendBroadcast(new Intent("com.farmerbb.taskbar.TOGGLE_DASHBOARD")));
    } else
        dashboardButton.setVisibility(View.GONE);

    if (pref.getBoolean("button_back", false)) {
        navbarButtonsEnabled = true;

        ImageView backButton = (ImageView) layout.findViewById(R.id.button_back);
        backButton.setVisibility(View.VISIBLE);
        backButton.setOnClickListener(v -> {
            U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_BACK);
            if (pref.getBoolean("hide_taskbar", true)
                    && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                hideTaskbar(true);
        });
    }

    if (pref.getBoolean("button_home", false)) {
        navbarButtonsEnabled = true;

        ImageView homeButton = (ImageView) layout.findViewById(R.id.button_home);
        homeButton.setVisibility(View.VISIBLE);
        homeButton.setOnClickListener(v -> {
            U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_HOME);
            if (pref.getBoolean("hide_taskbar", true)
                    && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                hideTaskbar(true);
        });

        homeButton.setOnLongClickListener(v -> {
            Intent voiceSearchIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
            voiceSearchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

            try {
                startActivity(voiceSearchIntent);
            } catch (ActivityNotFoundException e) {
                /* Gracefully fail */ }

            if (pref.getBoolean("hide_taskbar", true)
                    && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                hideTaskbar(true);

            return true;
        });

        homeButton.setOnGenericMotionListener((view13, motionEvent) -> {
            if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS
                    && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
                Intent voiceSearchIntent = new Intent(RecognizerIntent.ACTION_VOICE_SEARCH_HANDS_FREE);
                voiceSearchIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

                try {
                    startActivity(voiceSearchIntent);
                } catch (ActivityNotFoundException e) {
                    /* Gracefully fail */ }

                if (pref.getBoolean("hide_taskbar", true)
                        && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                    hideTaskbar(true);
            }
            return true;
        });
    }

    if (pref.getBoolean("button_recents", false)) {
        navbarButtonsEnabled = true;

        ImageView recentsButton = (ImageView) layout.findViewById(R.id.button_recents);
        recentsButton.setVisibility(View.VISIBLE);
        recentsButton.setOnClickListener(v -> {
            U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_RECENTS);
            if (pref.getBoolean("hide_taskbar", true)
                    && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                hideTaskbar(true);
        });

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
            recentsButton.setOnLongClickListener(v -> {
                U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN);
                if (pref.getBoolean("hide_taskbar", true)
                        && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                    hideTaskbar(true);

                return true;
            });

            recentsButton.setOnGenericMotionListener((view13, motionEvent) -> {
                if (motionEvent.getAction() == MotionEvent.ACTION_BUTTON_PRESS
                        && motionEvent.getButtonState() == MotionEvent.BUTTON_SECONDARY) {
                    U.sendAccessibilityAction(this, AccessibilityService.GLOBAL_ACTION_TOGGLE_SPLIT_SCREEN);
                    if (pref.getBoolean("hide_taskbar", true)
                            && !FreeformHackHelper.getInstance().isInFreeformWorkspace())
                        hideTaskbar(true);
                }
                return true;
            });
        }
    }

    if (!navbarButtonsEnabled)
        navbarButtons.setVisibility(View.GONE);

    layout.setBackgroundColor(backgroundTint);
    layout.findViewById(R.id.divider).setBackgroundColor(accentColor);
    button.setTextColor(accentColor);

    if (isFirstStart && FreeformHackHelper.getInstance().isInFreeformWorkspace())
        showTaskbar(false);
    else if (!pref.getBoolean("collapsed", false) && pref.getBoolean("taskbar_active", false))
        toggleTaskbar();

    LocalBroadcastManager.getInstance(this).unregisterReceiver(showReceiver);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(hideReceiver);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(tempShowReceiver);
    LocalBroadcastManager.getInstance(this).unregisterReceiver(tempHideReceiver);

    LocalBroadcastManager.getInstance(this).registerReceiver(showReceiver,
            new IntentFilter("com.farmerbb.taskbar.SHOW_TASKBAR"));
    LocalBroadcastManager.getInstance(this).registerReceiver(hideReceiver,
            new IntentFilter("com.farmerbb.taskbar.HIDE_TASKBAR"));
    LocalBroadcastManager.getInstance(this).registerReceiver(tempShowReceiver,
            new IntentFilter("com.farmerbb.taskbar.TEMP_SHOW_TASKBAR"));
    LocalBroadcastManager.getInstance(this).registerReceiver(tempHideReceiver,
            new IntentFilter("com.farmerbb.taskbar.TEMP_HIDE_TASKBAR"));

    startRefreshingRecents();

    windowManager.addView(layout, params);

    isFirstStart = false;
}

From source file:co.taqat.call.CallActivity.java

private void displayPausedCalls(Resources resources, final LinphoneCall call, int index) {
    // Control Row
    LinearLayout callView;

    if (call == null) {
        callView = (LinearLayout) inflater.inflate(R.layout.conference_paused_row, container, false);
        callView.setId(index + 1);//from  ww w  .ja v  a2  s  .c om
        callView.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View view) {
                pauseOrResumeConference();
            }
        });
    } else {
        callView = (LinearLayout) inflater.inflate(R.layout.call_inactive_row, container, false);
        callView.setId(index + 1);

        TextView contactName = (TextView) callView.findViewById(R.id.contact_name);
        ImageView contactImage = (ImageView) callView.findViewById(R.id.contact_picture);

        LinphoneAddress lAddress = call.getRemoteAddress();
        setContactInformation(contactName, contactImage, lAddress);
        displayCallStatusIconAndReturnCallPaused(callView, call);
        registerCallDurationTimer(callView, call);
    }
    callsList.addView(callView);
}

From source file:com.example.fan.horizontalscrollview.PagerSlidingTabStrip.java

private void addWarningTab(final int position, String title, int resId) {
    LinearLayout tabLayout = new LinearLayout(getContext());
    tabLayout.setOrientation(LinearLayout.HORIZONTAL);
    tabLayout.setGravity(Gravity.CENTER);

    ImageView tabImg = new ImageView(getContext());
    int width = DimenUtils.dp2px(getContext(), 18);
    LinearLayout.LayoutParams tabImgParams = new LinearLayout.LayoutParams(width, width);
    tabImgParams.setMargins(0, 0, DimenUtils.dp2px(getContext(), 10), 0);
    tabImgParams.gravity = Gravity.CENTER;
    tabImg.setLayoutParams(tabImgParams);
    if (resId != -1) {
        tabImg.setBackgroundResource(resId);
        tabImg.setVisibility(View.VISIBLE);
    } else {/* w  ww. jav  a 2  s.  co  m*/
        tabImg.setVisibility(View.GONE);
    }
    tabLayout.addView(tabImg, 0);

    TextView tab = new TextView(getContext());
    tab.setText(title);
    tab.setFocusable(true);
    tab.setGravity(Gravity.CENTER);
    tab.setSingleLine();
    tab.setTextColor(getResources().getColorStateList(
            mTextChangeable ? R.color.pst_tab_changeable_text_selector : R.color.pst_tab_text_selector));
    tab.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18.0f);
    tabLayout.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            if (null != mOnPageClickedLisener) {
                mOnPageClickedLisener.onPageClicked(position);
            }
            pager.setCurrentItem(position);
        }
    });
    tabLayout.addView(tab, 1);

    tabsContainer.addView(tabLayout);
}

From source file:com.hichinaschool.flashcards.anki.CardEditor.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    // Log.i(AnkiDroidApp.TAG, "CardEditor: onCreate");
    Themes.applyTheme(this);
    super.onCreate(savedInstanceState);

    this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    Intent intent = getIntent();/*  w  ww  .  j a  v  a2  s . c om*/
    if (savedInstanceState != null) {
        mCaller = savedInstanceState.getInt("caller");
        mAddNote = savedInstanceState.getBoolean("addFact");
    } else {
        mCaller = intent.getIntExtra(EXTRA_CALLER, CALLER_NOCALLER);
        if (mCaller == CALLER_NOCALLER) {
            String action = intent.getAction();
            if (action != null && (ACTION_CREATE_FLASHCARD.equals(action)
                    || ACTION_CREATE_FLASHCARD_SEND.equals(action))) {
                mCaller = CALLER_INDICLASH;
            }
        }
    }
    // Log.i(AnkiDroidApp.TAG, "CardEditor: caller: " + mCaller);

    SharedPreferences preferences = AnkiDroidApp.getSharedPrefs(getBaseContext());

    if (mCaller == CALLER_INDICLASH && preferences.getBoolean("intentAdditionInstantAdd", false)) {
        // save information without showing card editor
        fetchIntentInformation(intent);
        MetaDB.saveIntentInformation(CardEditor.this, Utils.joinFields(mSourceText));
        Themes.showThemedToast(CardEditor.this, getResources().getString(R.string.app_name) + ": "
                + getResources().getString(R.string.CardEditorLaterMessage), false);
        finish();
        return;
    }

    mCol = AnkiDroidApp.getCol();
    if (mCol == null) {
        reloadCollection(savedInstanceState);
        return;
    }

    registerExternalStorageListener();

    View mainView = getLayoutInflater().inflate(R.layout.card_editor, null);
    setContentView(mainView);
    Themes.setWallpaper(mainView);
    Themes.setContentStyle(mainView, Themes.CALLER_CARD_EDITOR);

    mFieldsLayoutContainer = (LinearLayout) findViewById(R.id.CardEditorEditFieldsLayout);

    mSave = (Button) findViewById(R.id.CardEditorSaveButton);
    mCancel = (Button) findViewById(R.id.CardEditorCancelButton);
    mLater = (Button) findViewById(R.id.CardEditorLaterButton);
    mDeckButton = (TextView) findViewById(R.id.CardEditorDeckText);
    mModelButton = (TextView) findViewById(R.id.CardEditorModelText);
    mTagsButton = (TextView) findViewById(R.id.CardEditorTagText);
    mSwapButton = (Button) findViewById(R.id.CardEditorSwapButton);
    mSwapButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            swapText(false);
        }
    });

    mAedictIntent = false;

    switch (mCaller) {
    case CALLER_NOCALLER:
        // Log.i(AnkiDroidApp.TAG, "CardEditor: no caller could be identified, closing");
        finish();
        return;

    case CALLER_REVIEWER:
        mCurrentEditedCard = Reviewer.getEditorCard();
        if (mCurrentEditedCard == null) {
            finish();
            return;
        }
        mEditorNote = mCurrentEditedCard.note();
        mAddNote = false;
        break;

    case CALLER_STUDYOPTIONS:
    case CALLER_DECKPICKER:
        mAddNote = true;
        break;

    case CALLER_BIGWIDGET_EDIT:
        // Card widgetCard = AnkiDroidWidgetBig.getCard();
        // if (widgetCard == null) {
        // finish();
        // return;
        // }
        // mEditorNote = widgetCard.getFact();
        // mAddNote = false;
        break;

    case CALLER_BIGWIDGET_ADD:
        mAddNote = true;
        break;

    case CALLER_CARDBROWSER_EDIT:
        mCurrentEditedCard = CardBrowser.sCardBrowserCard;
        if (mCurrentEditedCard == null) {
            finish();
            return;
        }
        mEditorNote = mCurrentEditedCard.note();
        mAddNote = false;
        break;

    case CALLER_CARDBROWSER_ADD:
        mAddNote = true;
        break;

    case CALLER_CARDEDITOR:
        mAddNote = true;
        break;

    case CALLER_CARDEDITOR_INTENT_ADD:
        mAddNote = true;
        break;

    case CALLER_INDICLASH:
        fetchIntentInformation(intent);
        if (mSourceText == null) {
            finish();
            return;
        }
        if (mSourceText[0].equals("Aedict Notepad") && addFromAedict(mSourceText[1])) {
            finish();
            return;
        }
        mAddNote = true;
        break;
    }

    setNote(mEditorNote);

    if (mAddNote) {
        setTitle(R.string.cardeditor_title_add_note);
        // set information transferred by intent
        String contents = null;
        if (mSourceText != null) {
            if (mAedictIntent && (mEditFields.size() == 3) && mSourceText[1].contains("[")) {
                contents = mSourceText[1].replaceFirst("\\[", "\u001f");
                contents = contents.substring(0, contents.length() - 1);
            } else {
                mEditFields.get(0).setText(mSourceText[0]);
                mEditFields.get(1).setText(mSourceText[1]);
            }
        } else {
            contents = intent.getStringExtra(EXTRA_CONTENTS);
        }
        if (contents != null) {
            setEditFieldTexts(contents);
        }

        LinearLayout modelButton = ((LinearLayout) findViewById(R.id.CardEditorModelButton));
        modelButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                showDialog(DIALOG_MODEL_SELECT);
            }
        });
        modelButton.setVisibility(View.VISIBLE);
        mSave.setText(getResources().getString(R.string.add));
        mCancel.setText(getResources().getString(R.string.close));

        mLater.setVisibility(View.VISIBLE);
        mLater.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String content = getFieldsText();
                if (content.length() > mEditFields.size() - 1) {
                    MetaDB.saveIntentInformation(CardEditor.this, content);
                    populateEditFields();
                    mSourceText = null;
                    Themes.showThemedToast(CardEditor.this,
                            getResources().getString(R.string.CardEditorLaterMessage), false);
                }
                if (mCaller == CALLER_INDICLASH || mCaller == CALLER_CARDEDITOR_INTENT_ADD) {
                    closeCardEditor();
                }
            }
        });
    } else {
        setTitle(R.string.cardeditor_title_edit_card);
        mSwapButton.setVisibility(View.GONE);
        mSwapButton = (Button) findViewById(R.id.CardEditorLaterButton);
        mSwapButton.setVisibility(View.VISIBLE);
        mSwapButton.setText(getResources().getString(R.string.fact_adder_swap));
        mSwapButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View v) {
                swapText(false);
            }
        });
    }

    ((LinearLayout) findViewById(R.id.CardEditorDeckButton)).setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            showDialog(DIALOG_DECK_SELECT);
        }
    });

    mPrefFixArabic = preferences.getBoolean("fixArabicText", false);
    // if Arabic reshaping is enabled, disable the Save button to avoid
    // saving the reshaped string to the deck
    if (mPrefFixArabic && !mAddNote) {
        mSave.setEnabled(false);
    }

    ((LinearLayout) findViewById(R.id.CardEditorTagButton)).setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            showDialog(DIALOG_TAGS_SELECT);
        }
    });

    mSave.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            if (duplicateCheck(true)) {
                return;
            }
            boolean modified = false;
            for (FieldEditText f : mEditFields) {
                modified = modified | f.updateField();
            }
            if (mAddNote) {
                DeckTask.launchDeckTask(DeckTask.TASK_TYPE_ADD_FACT, mSaveFactHandler,
                        new DeckTask.TaskData(mEditorNote));
            } else {
                // added tag?
                for (String t : mCurrentTags) {
                    modified = modified || !mEditorNote.hasTag(t);
                }
                // removed tag?
                modified = modified || mEditorNote.getTags().size() > mCurrentTags.size();
                // changed did?
                boolean changedDid = mCurrentEditedCard.getDid() != mCurrentDid;
                modified = modified || changedDid;
                if (modified) {
                    mEditorNote.setTags(mCurrentTags);
                    // set did for card
                    if (changedDid) {
                        mCurrentEditedCard.setDid(mCurrentDid);
                    }
                    mChanged = true;
                }
                closeCardEditor();
                // if (mCaller == CALLER_BIGWIDGET_EDIT) {
                // // DeckTask.launchDeckTask(DeckTask.TASK_TYPE_UPDATE_FACT,
                // // mSaveFactHandler, new
                // // DeckTask.TaskData(Reviewer.UPDATE_CARD_SHOW_QUESTION,
                // // mDeck, AnkiDroidWidgetBig.getCard()));
                // } else if (!mCardReset) {
                // // Only send result to save if something was actually
                // // changed
                // if (mModified) {
                // setResult(RESULT_OK);
                // } else {
                // setResult(RESULT_CANCELED);
                // }
                // closeCardEditor();
                // }

            }
        }
    });

    mCancel.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            closeCardEditor();
        }

    });
}

From source file:org.zywx.wbpalmstar.plugin.uexPopoverMenu.EUExPopoverMenu.java

private void showPopoverMenu(double x, double y, int direction, String bgColorStr, String dividerColor,
        String textColor, int textSize, JSONArray data) {
    LinearLayout rootView = (LinearLayout) LayoutInflater.from(mContext)
            .inflate(finder.getLayoutId("plugin_uex_popovermenu"), null);

    final PopupWindow popupWindow = new PopupWindow(rootView, LinearLayout.LayoutParams.WRAP_CONTENT,
            LinearLayout.LayoutParams.WRAP_CONTENT, true);

    popupWindow.setContentView(rootView);
    ///*from  w  ww .j a  v a2 s  .c  om*/
    rootView.setBackgroundColor(Color.parseColor(bgColorStr));
    popupWindow.setContentView(rootView);
    //popupWindow?
    popupWindow.setBackgroundDrawable(new BitmapDrawable());
    popupWindow.setOutsideTouchable(true);

    int length = data.length();
    List<ItemData> itemDataList = new ArrayList<ItemData>();
    try {
        for (int i = 0; i < length; i++) {
            ItemData item = new ItemData();
            String icon = data.getJSONObject(i).optString("icon", "");
            if (!hasIcon && !TextUtils.isEmpty(icon)) {
                hasIcon = true;
            }
            if (hasIcon) {
                item.setIcon(data.getJSONObject(i).getString("icon"));
            }
            item.setText(data.getJSONObject(i).getString("text"));
            itemDataList.add(item);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }

    for (int i = 0; i < length; i++) {
        LinearLayout linearLayout = new LinearLayout(mContext);
        linearLayout.setOrientation(LinearLayout.HORIZONTAL);
        linearLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                LinearLayout.LayoutParams.WRAP_CONTENT));

        if (hasIcon) {
            ImageView imageView = new ImageView(mContext);
            imageView.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT));
            String imagePath = itemDataList.get(i).getIcon();
            imageView.setImageBitmap(getBitmapFromPath(imagePath));
            imageView.setPadding(DensityUtil.dip2px(mContext, 5), 0, 0, 0);
            linearLayout.addView(imageView);
        }
        TextView tvText = new TextView(mContext);
        LinearLayout.LayoutParams tvLayoutParams = new LinearLayout.LayoutParams(
                LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        tvLayoutParams.gravity = Gravity.CENTER_VERTICAL;
        tvText.setLayoutParams(tvLayoutParams);

        tvText.setPadding(DensityUtil.dip2px(mContext, 5), 0, DensityUtil.dip2px(mContext, 8), 0);
        tvText.setText(itemDataList.get(i).getText());
        tvText.setTextColor(Color.parseColor(textColor));
        tvText.setTextSize(textSize);
        linearLayout.addView(tvText);
        linearLayout.setTag(i);
        linearLayout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                callBackPluginJs(CALLBACK_ITEM_SELECTED, String.valueOf(v.getTag()));
                if (popupWindow != null && popupWindow.isShowing()) {
                    popupWindow.dismiss();
                }
            }
        });
        rootView.addView(linearLayout);

        //
        View dividerLine = new View(mContext);
        dividerLine.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                DensityUtil.dip2px(mContext, 1)));
        dividerLine.setBackgroundColor(Color.parseColor(dividerColor));
        rootView.addView(dividerLine);
    }
    int gravityParam;
    switch (direction) {
    case 0:
        gravityParam = Gravity.LEFT | Gravity.TOP;
        break;
    case 1:
        gravityParam = Gravity.RIGHT | Gravity.TOP;
        break;
    case 2:
        gravityParam = Gravity.LEFT | Gravity.BOTTOM;
        break;
    case 3:
        gravityParam = Gravity.RIGHT | Gravity.BOTTOM;
        break;
    default:
        gravityParam = Gravity.LEFT | Gravity.TOP;
        break;
    }
    popupWindow.showAtLocation(mBrwView.getRootView(), gravityParam, (int) x, (int) y);
}

From source file:com.mishiranu.dashchan.ui.navigator.NavigatorActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void showThemeDialog() {
    final int checkedItem = Arrays.asList(Preferences.VALUES_THEME).indexOf(Preferences.getTheme());
    Resources resources = getResources();
    float density = ResourceUtils.obtainDensity(resources);
    ScrollView scrollView = new ScrollView(this);
    LinearLayout outer = new LinearLayout(this);
    outer.setOrientation(LinearLayout.VERTICAL);
    int outerPadding = (int) (16f * density);
    outer.setPadding(outerPadding, outerPadding, outerPadding, outerPadding);
    scrollView.addView(outer, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
    final AlertDialog dialog = new AlertDialog.Builder(this).setTitle(R.string.action_change_theme)
            .setView(scrollView).setNegativeButton(android.R.string.cancel, null).create();
    View.OnClickListener listener = v -> {
        int index = (int) v.getTag();
        if (index != checkedItem) {
            Preferences.setTheme(Preferences.VALUES_THEME[index]);
            recreate();/*from ww w. j  a v a 2 s .co  m*/
        }
        dialog.dismiss();
    };
    int circleSize = (int) (56f * density);
    int itemPadding = (int) (12f * density);
    LinearLayout inner = null;
    for (int i = 0; i < Preferences.ENTRIES_THEME.length; i++) {
        if (i % 3 == 0) {
            inner = new LinearLayout(this);
            inner.setOrientation(LinearLayout.HORIZONTAL);
            outer.addView(inner, LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);
        }
        LinearLayout layout = new LinearLayout(this);
        layout.setOrientation(LinearLayout.VERTICAL);
        layout.setGravity(Gravity.CENTER);
        layout.setBackgroundResource(
                ResourceUtils.getResourceId(this, android.R.attr.selectableItemBackground, 0));
        layout.setPadding(0, itemPadding, 0, itemPadding);
        layout.setOnClickListener(listener);
        layout.setTag(i);
        inner.addView(layout, new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.WRAP_CONTENT, 1f));
        View view = new View(this);
        int colorBackgroundAttr = Preferences.VALUES_THEME_COLORS[i][0];
        int colorPrimaryAttr = Preferences.VALUES_THEME_COLORS[i][1];
        int colorAccentAttr = Preferences.VALUES_THEME_COLORS[i][2];
        Resources.Theme theme = getResources().newTheme();
        theme.applyStyle(Preferences.VALUES_THEME_IDS[i], true);
        TypedArray typedArray = theme
                .obtainStyledAttributes(new int[] { colorBackgroundAttr, colorPrimaryAttr, colorAccentAttr });
        view.setBackground(new ThemeChoiceDrawable(typedArray.getColor(0, 0), typedArray.getColor(1, 0),
                typedArray.getColor(2, 0)));
        typedArray.recycle();
        if (C.API_LOLLIPOP) {
            view.setElevation(6f * density);
        }
        layout.addView(view, circleSize, circleSize);
        TextView textView = new TextView(this, null, android.R.attr.textAppearanceListItem);
        textView.setSingleLine(true);
        textView.setEllipsize(TextUtils.TruncateAt.END);
        textView.setText(Preferences.ENTRIES_THEME[i]);
        if (C.API_LOLLIPOP) {
            textView.setAllCaps(true);
            textView.setTypeface(GraphicsUtils.TYPEFACE_MEDIUM);
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 12f);
        } else {
            textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 14f);
        }
        textView.setGravity(Gravity.CENTER_HORIZONTAL);
        textView.setPadding(0, (int) (8f * density), 0, 0);
        layout.addView(textView, LinearLayout.LayoutParams.MATCH_PARENT,
                LinearLayout.LayoutParams.WRAP_CONTENT);
        if (i + 1 == Preferences.ENTRIES_THEME.length && Preferences.ENTRIES_THEME.length % 3 != 0) {
            if (Preferences.ENTRIES_THEME.length % 3 == 1) {
                inner.addView(new View(this), 0,
                        new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f));
            }
            inner.addView(new View(this),
                    new LinearLayout.LayoutParams(0, LinearLayout.LayoutParams.MATCH_PARENT, 1f));
        }
    }
    dialog.show();
}

From source file:com.google.sample.devicelab.MainActivity.java

private void refreshUI() {
    mLoginProgressBar.setVisibility(View.GONE);
    mLoginStatus.setVisibility(View.GONE);
    mLogoutProgressBar.setVisibility(View.GONE);
    mLogoutStatus.setVisibility(View.GONE);

    LinearLayout loggedOut = (LinearLayout) findViewById(R.id.loggedOut);
    LinearLayout loggedIn = (LinearLayout) findViewById(R.id.loggedIn);
    if (UserSettings.isDeviceAddedToLab(this)) {
        loggedIn.setVisibility(View.VISIBLE);
        loggedOut.setVisibility(View.GONE);

    } else {//from w  ww.j  a v a2  s . co  m
        loggedIn.setVisibility(View.GONE);
        loggedOut.setVisibility(View.VISIBLE);

        String appEngineId = UserSettings.getAppEngineId(this);
        LinearLayout gaeVerifyingLL = (LinearLayout) findViewById(R.id.gaeVerificationLL);

        if (appEngineId.equals("")) {
            ((TextView) findViewById(R.id.gaeUrl)).setText(R.string.gae_id_label_hint);
            gaeVerifyingLL.setVisibility(View.GONE);
        } else {
            ((TextView) findViewById(R.id.gaeUrl)).setText(appEngineId);
            gaeVerifyingLL.setVisibility(View.VISIBLE);
            ((TextView) findViewById(R.id.gaeNumber)).setText(UserSettings.getAppEngineNumber(this));

            //Update the UI for the gaeVerification linear layout
            TextView verificationStatus = (TextView) findViewById(R.id.gaeVerificationStatus);
            ProgressBar verificationProgressBar = (ProgressBar) findViewById(R.id.gaeVerificationProgress);
            GAEIdVerificationStatus idStatus = UserSettings.getAppEngineIdStatus(this);
            verificationStatus.setText(idStatus.getDisplayString(this));
            verificationProgressBar.setVisibility(idStatus.showProgressBar() ? View.VISIBLE : View.GONE);

            //We set on click listened to redo verification
            gaeVerifyingLL.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    new GAEIdVerifier(MainActivity.this).execute();
                }
            });

            //If verification passed, we allow user to log in; otherwise, we block it
            TextView loginDescription = (TextView) findViewById(R.id.loginDescription);
            SignInButton signInButton = (SignInButton) findViewById(R.id.signInButton);
            if (idStatus == GAEIdVerificationStatus.VERIFICATION_PASSED
                    && UserSettings.getAppEngineNumber(this).equals("")) {
                loginDescription.setText(R.string.description_logged_out4);
                signInButton.setVisibility(View.GONE);
            } else if (idStatus == GAEIdVerificationStatus.VERIFICATION_PASSED) {
                loginDescription.setText(R.string.description_logged_out3);
                signInButton.setVisibility(View.VISIBLE);
            } else {
                loginDescription.setText(R.string.description_logged_out2);
                signInButton.setVisibility(View.GONE);
            }

            //Show reason logged in failed
            if (!UserSettings.getLoginFailureReason(this).equals("")
                    && idStatus == GAEIdVerificationStatus.VERIFICATION_PASSED) {
                mLoginStatus.setVisibility(View.VISIBLE);
                mLoginStatus.setText(UserSettings.getLoginFailureReason(this));
            }
        }

    }

}