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

Commit 2d01de75 authored by Ethan Chen's avatar Ethan Chen Committed by Abhisek Devkota
Browse files

SystemUI: Update UserTile from Google 4.4 code

Change-Id: I867167b83897636a3e28d08849e018a3b25caad7
parent cebde37a
Loading
Loading
Loading
Loading
+25 −23
Original line number Diff line number Diff line
@@ -16,6 +16,7 @@ import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Handler;
import android.os.RemoteException;
import android.os.UserHandle;
import android.os.UserManager;
@@ -40,38 +41,46 @@ public class UserTile extends QuickSettingsTile {

    private static final String TAG = "UserTile";
    private static final String INTENT_EXTRA_NEW_LOCAL_PROFILE = "newLocalProfile";
    private Handler mHandler;
    private Drawable userAvatar;
    private AsyncTask<Void, Void, Pair<String, Drawable>> mUserInfoTask;

    public UserTile(Context context, QuickSettingsController qsc) {
    public UserTile(Context context, QuickSettingsController qsc, Handler handler) {
        super(context, qsc, R.layout.quick_settings_tile_user);

        mHandler = handler;
        mOnClick = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mQsc.mBar.collapseAllPanels(true);
                final UserManager um =
                        (UserManager) mContext.getSystemService(Context.USER_SERVICE);
                int numUsers = um.getUsers(true).size();
                if (numUsers <= 1) {
                final UserManager um = UserManager.get(mContext);
                if (um.getUsers(true).size() > 1) {
                    // Since keyguard and systemui were merged into the same process to save
                    // memory, they share the same Looper and graphics context.  As a result,
                    // there's no way to allow concurrent animation while keyguard inflates.
                    // The workaround is to add a slight delay to allow the animation to finish.
                    mHandler.postDelayed(new Runnable() {
                        public void run() {
                            try {
                                WindowManagerGlobal.getWindowManagerService().lockNow(null);
                            } catch (RemoteException e) {
                                Log.e(TAG, "Couldn't show user switcher", e);
                            }
                        }
                    }, 400); // TODO: ideally this would be tied to the collapse of the panel
                } else {
                    final Cursor cursor = mContext.getContentResolver().query(
                            Profile.CONTENT_URI, null, null, null, null);
                    if (cursor.moveToNext() && !cursor.isNull(0)) {
                        Intent intent = new Intent(Intent.ACTION_VIEW, ContactsContract.Profile.CONTENT_URI);
                        startSettingsActivity(intent);
                        Intent intent = ContactsContract.QuickContact.composeQuickContactsIntent(
                                mContext, v, ContactsContract.Profile.CONTENT_URI,
                                ContactsContract.QuickContact.MODE_LARGE, null);
                        mContext.startActivityAsUser(intent, new UserHandle(UserHandle.USER_CURRENT));
                    } else {
                        Intent intent = new Intent(Intent.ACTION_INSERT, Contacts.CONTENT_URI);
                        intent.putExtra(INTENT_EXTRA_NEW_LOCAL_PROFILE, true);
                        startSettingsActivity(intent);
                    }
                    cursor.close();
                } else {
                    try {
                        WindowManagerGlobal.getWindowManagerService().lockNow(
                                null);
                    } catch (RemoteException e) {
                        Log.e(TAG, "Couldn't show user switcher", e);
                    }
                }
            }
        };
@@ -123,14 +132,7 @@ public class UserTile extends QuickSettingsTile {
        mUserInfoTask = new AsyncTask<Void, Void, Pair<String, Drawable>>() {
            @Override
            protected Pair<String, Drawable> doInBackground(Void... params) {
                try {
                    // The system needs some time to change the picture, if we try to load it when we receive the broadcast, we will load the old one
                    Thread.sleep(50);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                final UserManager um =
                        (UserManager) mContext.getSystemService(Context.USER_SERVICE);
                final UserManager um = UserManager.get(mContext);

                String name = null;
                Drawable avatar = null;
+1 −1
Original line number Diff line number Diff line
@@ -211,7 +211,7 @@ public class QuickSettingsController {
        for (String tile : tiles.split("\\|")) {
            QuickSettingsTile qs = null;
            if (tile.equals(TILE_USER)) {
                qs = new UserTile(mContext, this);
                qs = new UserTile(mContext, this, mHandler);
            } else if (tile.equals(TILE_BATTERY)) {
                qs = new BatteryTile(mContext, this, mStatusBarService.mBatteryController);
            } else if (tile.equals(TILE_SETTINGS)) {