Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 4aae4321 authored by Danesh M's avatar Danesh M Committed by Gerrit Code Review
Browse files

SystemUI : Show create profile if user doesn't have one setup

Change-Id: I35439b402e645970721dea0505b805a899ec3275
parent 47e7161f
Loading
Loading
Loading
Loading
+18 −3
Original line number Diff line number Diff line
@@ -30,6 +30,7 @@ import android.widget.FrameLayout;
import com.android.systemui.R;
import com.android.systemui.qs.QSPanel;
import com.android.systemui.statusbar.policy.KeyguardUserSwitcher;
import com.android.systemui.statusbar.policy.UserInfoController;
import com.android.systemui.statusbar.policy.UserSwitcherController;

/**
@@ -37,12 +38,17 @@ import com.android.systemui.statusbar.policy.UserSwitcherController;
 */
public class MultiUserSwitch extends FrameLayout implements View.OnClickListener {

    public static final String INTENT_EXTRA_NEW_LOCAL_PROFILE = "newLocalProfile";

    private QSPanel mQsPanel;
    private KeyguardUserSwitcher mKeyguardUserSwitcher;
    private boolean mKeyguardMode;
    final UserManager mUserManager;
    private ActivityStarter mActivityStarter;


    private UserInfoController mUserInfoController;

    public MultiUserSwitch(Context context, AttributeSet attrs) {
        super(context, attrs);
        mUserManager = UserManager.get(getContext());
@@ -87,9 +93,15 @@ public class MultiUserSwitch extends FrameLayout implements View.OnClickListener
                }
            }
        } else {
            Intent intent = ContactsContract.QuickContact.composeQuickContactsIntent(
            Intent intent;
            if (mUserInfoController == null || mUserInfoController.isProfileSetup()) {
                intent = ContactsContract.QuickContact.composeQuickContactsIntent(
                        getContext(), v, ContactsContract.Profile.CONTENT_URI,
                        ContactsContract.QuickContact.MODE_LARGE, null);
            } else {
                intent = new Intent(Intent.ACTION_INSERT, ContactsContract.Contacts.CONTENT_URI);
                intent.putExtra(INTENT_EXTRA_NEW_LOCAL_PROFILE, true);
            }
            if (mActivityStarter != null) {
                mActivityStarter.startActivity(intent, true /* dismissShade */);
            } else {
@@ -135,4 +147,7 @@ public class MultiUserSwitch extends FrameLayout implements View.OnClickListener
        return false;
    }

    public void setUserInfoController(UserInfoController userInfoController) {
        mUserInfoController = userInfoController;
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -572,6 +572,9 @@ public class StatusBarHeaderView extends RelativeLayout implements View.OnClickL
    public void setUserInfoController(UserInfoController userInfoController) {
        mUserInfoController = userInfoController;
        userInfoController.addListener(mUserInfoChangedListener);
        if (mMultiUserSwitch != null) {
            mMultiUserSwitch.setUserInfoController(mUserInfoController);
        }
    }

    @Override
+21 −17
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@ public final class UserInfoController {
    private boolean mUseDefaultAvatar;
    private String mUserName;
    private Drawable mUserDrawable;
    private boolean mProfileSetup;

    public UserInfoController(Context context) {
        mContext = context;
@@ -162,9 +163,8 @@ public final class UserInfoController {
                    mUseDefaultAvatar = true;
                }

                // If it's a single-user device, get the profile name, since the nickname is not
                // usually valid
                if (um.getUsers().size() <= 1) {
                mProfileSetup = false;

                // Try and read the display name from the local profile
                final Cursor cursor = context.getContentResolver().query(
                        ContactsContract.Profile.CONTENT_URI, new String[] {
@@ -174,6 +174,7 @@ public final class UserInfoController {
                if (cursor != null) {
                    try {
                        if (cursor.moveToFirst()) {
                            mProfileSetup = true;
                            name = cursor.getString(cursor.getColumnIndex(
                                    ContactsContract.CommonDataKinds.Phone.DISPLAY_NAME));
                        }
@@ -181,7 +182,6 @@ public final class UserInfoController {
                        cursor.close();
                    }
                }
                }
                return new Pair<String, Drawable>(name, avatar);
            }

@@ -202,6 +202,10 @@ public final class UserInfoController {
        }
    }

    public boolean isProfileSetup() {
        return mProfileSetup;
    }

    public interface OnUserInfoChangedListener {
        public void onUserInfoChanged(String name, Drawable picture);
    }