Example usage for android.widget LinearLayout indexOfChild

List of usage examples for android.widget LinearLayout indexOfChild

Introduction

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

Prototype

public int indexOfChild(View child) 

Source Link

Document

Returns the position in the group of the specified child view.

Usage

From source file:org.matrix.console.activity.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (CommonActivityUtils.shouldRestartApp()) {
        Log.e(LOG_TAG, "Restart the application.");
        CommonActivityUtils.restartApp(this);
    }/*from www.  ja v a  2 s.  com*/

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_settings);

    mMediasCache = Matrix.getInstance(this).getMediasCache();

    // add any known session
    LinearLayout globalLayout = (LinearLayout) findViewById(R.id.settings_layout);
    TextView profileHeader = (TextView) findViewById(R.id.settings_profile_information_header);
    int pos = globalLayout.indexOfChild(profileHeader);

    for (MXSession session : Matrix.getMXSessions(this)) {
        final MXSession fSession = session;

        LinearLayout profileLayout = (LinearLayout) getLayoutInflater()
                .inflate(R.layout.account_section_settings, null);
        mLinearLayoutByMatrixId.put(session.getCredentials().userId, profileLayout);

        pos++;
        globalLayout.addView(profileLayout, pos);
        refreshProfileThumbnail(session, profileLayout);

        ImageView avatarView = (ImageView) profileLayout.findViewById(R.id.imageView_avatar);

        avatarView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mUpdatingSessionId = fSession.getCredentials().userId;
                Intent fileIntent = new Intent(Intent.ACTION_PICK);
                fileIntent.setType("image/*");
                startActivityForResult(fileIntent, REQUEST_IMAGE);
            }
        });

        MyUser myUser = session.getMyUser();

        TextView matrixIdTextView = (TextView) profileLayout.findViewById(R.id.textView_matrix_id);
        matrixIdTextView.setText(myUser.userId);

        final Button saveButton = (Button) profileLayout.findViewById(R.id.button_save);

        EditText displayNameEditText = (EditText) profileLayout.findViewById(R.id.editText_displayName);
        displayNameEditText.setText(myUser.displayname);
        displayNameEditText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                updateSaveButton(saveButton);
            }

            @Override
            public void afterTextChanged(Editable s) {
            }
        });

        saveButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                saveChanges(fSession);
            }
        });
    }

    // Config information

    String versionName = "";

    try {
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        versionName = pInfo.versionName;
    } catch (Exception e) {

    }

    TextView consoleVersionTextView = (TextView) findViewById(R.id.textView_matrixConsoleVersion);
    consoleVersionTextView.setText(getString(R.string.settings_config_console_version, versionName));

    TextView sdkVersionTextView = (TextView) findViewById(R.id.textView_matrixSDKVersion);
    sdkVersionTextView.setText(getString(R.string.settings_config_sdk_version, versionName));

    TextView buildNumberTextView = (TextView) findViewById(R.id.textView_matrixBuildNumber);
    buildNumberTextView.setText(getString(R.string.settings_config_build_number, ""));

    TextView userIdTextView = (TextView) findViewById(R.id.textView_configUsers);
    String config = "";

    int sessionIndex = 1;

    Collection<MXSession> sessions = Matrix.getMXSessions(this);

    for (MXSession session : sessions) {

        if (sessions.size() > 1) {
            config += "\nAccount " + sessionIndex + " : \n";
            sessionIndex++;
        }

        config += String.format(getString(R.string.settings_config_home_server),
                session.getHomeserverConfig().getHomeserverUri().toString());
        config += "\n";

        config += String.format(getString(R.string.settings_config_user_id), session.getMyUser().userId);

        if (sessions.size() > 1) {
            config += "\n";
        }
    }

    userIdTextView.setText(config);

    // room settings
    final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

    listenBoxUpdate(preferences, R.id.checkbox_useGcm,
            getString(R.string.settings_key_use_google_cloud_messaging), true);
    listenBoxUpdate(preferences, R.id.checkbox_displayAllEvents,
            getString(R.string.settings_key_display_all_events), false);
    listenBoxUpdate(preferences, R.id.checkbox_hideUnsupportedEvenst,
            getString(R.string.settings_key_hide_unsupported_events), true);
    listenBoxUpdate(preferences, R.id.checkbox_sortByLastSeen,
            getString(R.string.settings_key_sort_by_last_seen), true);
    listenBoxUpdate(preferences, R.id.checkbox_displayLeftMembers,
            getString(R.string.settings_key_display_left_members), false);
    listenBoxUpdate(preferences, R.id.checkbox_displayPublicRooms,
            getString(R.string.settings_key_display_public_rooms_recents), true);
    listenBoxUpdate(preferences, R.id.checkbox_rageshake, getString(R.string.settings_key_use_rage_shake),
            true);

    final Button clearCacheButton = (Button) findViewById(R.id.button_clear_cache);

    clearCacheButton.setText(getString(R.string.clear_cache) + " (" + computeApplicationCacheSize() + ")");

    clearCacheButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Matrix.getInstance(SettingsActivity.this).reloadSessions(SettingsActivity.this);
        }
    });

    final Button notificationsRuleButton = (Button) findViewById(R.id.button_notifications_rule);

    notificationsRuleButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            launchNotificationsActivity();
        }
    });

    final GcmRegistrationManager gcmRegistrationManager = Matrix.getInstance(this)
            .getSharedGcmRegistrationManager();

    refreshGCMEntries();

    managePedingGCMregistration();
}

From source file:im.vector.activity.SettingsActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (CommonActivityUtils.shouldRestartApp()) {
        Log.e(LOG_TAG, "Restart the application.");
        CommonActivityUtils.restartApp(this);
    }/*w w  w .  j  a  v a  2s  . c  om*/

    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_settings);

    mMediasCache = Matrix.getInstance(this).getMediasCache();

    // add any known session
    LinearLayout globalLayout = (LinearLayout) findViewById(R.id.settings_layout);
    TextView profileHeader = (TextView) findViewById(R.id.settings_profile_information_header);
    int pos = globalLayout.indexOfChild(profileHeader);

    for (MXSession session : Matrix.getMXSessions(this)) {
        final MXSession fSession = session;

        LinearLayout profileLayout = (LinearLayout) getLayoutInflater()
                .inflate(R.layout.account_section_settings, null);
        mLinearLayoutBySession.put(session, profileLayout);

        pos++;
        globalLayout.addView(profileLayout, pos);
        refreshProfileThumbnail(session, profileLayout);

        ImageView avatarView = (ImageView) profileLayout.findViewById(R.id.imageView_avatar);

        avatarView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mUpdatingSession = fSession;
                Intent fileIntent = new Intent(Intent.ACTION_PICK);
                fileIntent.setType("image/*");
                startActivityForResult(fileIntent, REQUEST_IMAGE);
            }
        });

        MyUser myUser = session.getMyUser();

        TextView matrixIdTextView = (TextView) profileLayout.findViewById(R.id.textView_matrix_id);
        matrixIdTextView.setText(myUser.userId);

        final Button saveButton = (Button) profileLayout.findViewById(R.id.button_save);

        EditText displayNameEditText = (EditText) profileLayout.findViewById(R.id.editText_displayName);
        displayNameEditText.setText(myUser.displayname);
        displayNameEditText.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }

            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                updateSaveButton(saveButton);
            }

            @Override
            public void afterTextChanged(Editable s) {
            }
        });

        saveButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                saveChanges(fSession);
            }
        });
    }

    // Config information

    String versionName = "";

    try {
        PackageInfo pInfo = getPackageManager().getPackageInfo(getPackageName(), 0);
        versionName = pInfo.versionName;
    } catch (Exception e) {

    }

    TextView consoleVersionTextView = (TextView) findViewById(R.id.textView_matrixConsoleVersion);
    consoleVersionTextView.setText(getString(R.string.settings_config_console_version, versionName));

    TextView sdkVersionTextView = (TextView) findViewById(R.id.textView_matrixSDKVersion);
    sdkVersionTextView.setText(getString(R.string.settings_config_sdk_version, versionName));

    TextView buildNumberTextView = (TextView) findViewById(R.id.textView_matrixBuildNumber);
    buildNumberTextView.setText(getString(R.string.settings_config_build_number, ""));

    TextView userIdTextView = (TextView) findViewById(R.id.textView_configUsers);
    String config = "";

    int sessionIndex = 1;

    Collection<MXSession> sessions = Matrix.getMXSessions(this);

    for (MXSession session : sessions) {

        if (sessions.size() > 1) {
            config += "\nAccount " + sessionIndex + " : \n";
            sessionIndex++;
        }

        config += String.format(getString(R.string.settings_config_home_server),
                session.getCredentials().homeServer);
        config += "\n";

        config += String.format(getString(R.string.settings_config_user_id), session.getMyUser().userId);

        if (sessions.size() > 1) {
            config += "\n";
        }
    }

    userIdTextView.setText(config);

    // room settings
    final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);

    listenBoxUpdate(preferences, R.id.checkbox_useGcm,
            getString(R.string.settings_key_use_google_cloud_messaging), true);
    listenBoxUpdate(preferences, R.id.checkbox_displayAllEvents,
            getString(R.string.settings_key_display_all_events), false);
    listenBoxUpdate(preferences, R.id.checkbox_hideUnsupportedEvenst,
            getString(R.string.settings_key_hide_unsupported_events), true);
    listenBoxUpdate(preferences, R.id.checkbox_sortByLastSeen,
            getString(R.string.settings_key_sort_by_last_seen), true);
    listenBoxUpdate(preferences, R.id.checkbox_displayLeftMembers,
            getString(R.string.settings_key_display_left_members), false);
    listenBoxUpdate(preferences, R.id.checkbox_displayPublicRooms,
            getString(R.string.settings_key_display_public_rooms_recents), true);

    final Button clearCacheButton = (Button) findViewById(R.id.button_clear_cache);

    clearCacheButton.setText(getString(R.string.clear_cache) + " (" + computeApplicationCacheSize() + ")");

    clearCacheButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Matrix.getInstance(SettingsActivity.this).reloadSessions(SettingsActivity.this);
        }
    });

    final Button notificationsRuleButton = (Button) findViewById(R.id.button_notifications_rule);

    notificationsRuleButton.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            launchNotificationsActivity();
        }
    });

    final GcmRegistrationManager gcmRegistrationManager = Matrix.getInstance(this)
            .getSharedGcmRegistrationManager();

    refreshGCMEntries();

    final EditText pusherUrlEditText = (EditText) findViewById(R.id.editText_gcm_pusher_url);
    pusherUrlEditText.addTextChangedListener(new TextWatcher() {

        public void afterTextChanged(Editable s) {
            gcmRegistrationManager.setPusherUrl(pusherUrlEditText.getText().toString());
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    final EditText pusherProfileEditText = (EditText) findViewById(R.id.editText_gcm_pusher_profile_tag);
    pusherProfileEditText.addTextChangedListener(new TextWatcher() {

        public void afterTextChanged(Editable s) {
            gcmRegistrationManager.setPusherFileTag(pusherProfileEditText.getText().toString());
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
        }
    });

    managePedingGCMregistration();
}