Example usage for android.content ComponentName equals

List of usage examples for android.content ComponentName equals

Introduction

In this page you can find the example usage for android.content ComponentName equals.

Prototype

@Override
    public boolean equals(Object obj) 

Source Link

Usage

From source file:com.google.android.apps.dashclock.DashClockService.java

private void enforceEnabledExtensionForCallback(IDataConsumerHostCallback cb, ComponentName extension) {
    enforceRegisteredCallingCallback(cb);
    List<ComponentName> extensions = mRegisteredCallbacks.get(cb.asBinder()).mExtensions;
    for (ComponentName ext : extensions) {
        if (ext.equals(extension)) {
            return;
        }//from w  ww.ja v a2s  . co  m
    }
    throw new SecurityException("Extension is not enabled for caller.");
}

From source file:com.google.android.apps.dashclock.DashClockService.java

private ExtensionListing findExtensionInfo(ComponentName extension) {
    for (ExtensionListing info : mExtensionManager.getAvailableExtensions()) {
        if (extension.equals(info.componentName())) {
            return info;
        }/*from   w ww  . j  av  a2  s. co m*/
    }
    return null;
}

From source file:com.android.server.telecom.testapps.TestConnectionService.java

@Override
public Connection onCreateUnknownConnection(PhoneAccountHandle connectionManagerPhoneAccount,
        final ConnectionRequest request) {
    PhoneAccountHandle accountHandle = request.getAccountHandle();
    ComponentName componentName = new ComponentName(this, TestConnectionService.class);
    if (accountHandle != null && componentName.equals(accountHandle.getComponentName())) {
        final TestConnection connection = new TestConnection(false);
        final Bundle extras = request.getExtras();
        final Uri providedHandle = extras.getParcelable(EXTRA_HANDLE);

        Uri handle = providedHandle == null
                ? Uri.fromParts(PhoneAccount.SCHEME_TEL, getDummyNumber(false), null)
                : providedHandle;/*from www .  j  a  v a2s.c o m*/

        connection.setAddress(handle, TelecomManager.PRESENTATION_ALLOWED);
        connection.setDialing();

        addCall(connection);
        return connection;
    } else {
        return Connection.createFailedConnection(new DisconnectCause(DisconnectCause.ERROR,
                "Invalid inputs: " + accountHandle + " " + componentName));
    }
}

From source file:com.android.server.telecom.testapps.TestConnectionService.java

@Override
public Connection onCreateIncomingConnection(PhoneAccountHandle connectionManagerAccount,
        final ConnectionRequest request) {
    PhoneAccountHandle accountHandle = request.getAccountHandle();
    ComponentName componentName = new ComponentName(this, TestConnectionService.class);

    if (accountHandle != null && componentName.equals(accountHandle.getComponentName())) {
        final TestConnection connection = new TestConnection(true);
        // Get the stashed intent extra that determines if this is a video call or audio call.
        Bundle extras = request.getExtras();
        boolean isVideoCall = extras.getBoolean(EXTRA_IS_VIDEO_CALL);
        Uri providedHandle = extras.getParcelable(EXTRA_HANDLE);

        // Use dummy number for testing incoming calls.
        Uri address = providedHandle == null
                ? Uri.fromParts(PhoneAccount.SCHEME_TEL, getDummyNumber(isVideoCall), null)
                : providedHandle;/*from   w w w .j  a v  a  2s. c  o  m*/

        int videoState = isVideoCall ? VideoProfile.STATE_BIDIRECTIONAL : VideoProfile.STATE_AUDIO_ONLY;
        connection.setVideoState(videoState);
        setAddress(connection, address);

        addVideoProvider(connection);

        addCall(connection);

        ConnectionRequest newRequest = new ConnectionRequest(request.getAccountHandle(), address,
                request.getExtras(), videoState);
        connection.setVideoState(videoState);
        return connection;
    } else {
        return Connection.createFailedConnection(new DisconnectCause(DisconnectCause.ERROR,
                "Invalid inputs: " + accountHandle + " " + componentName));
    }
}

From source file:com.google.android.apps.muzei.settings.SettingsChooseSourceFragment.java

private void updateSelectedItem(boolean allowAnimate) {
    ComponentName previousSelectedSource = mSelectedSource;
    mSelectedSource = mSourceManager.getSelectedSource();
    if (previousSelectedSource != null && previousSelectedSource.equals(mSelectedSource)) {
        // Only update status
        for (final Source source : mSources) {
            if (!source.componentName.equals(mSelectedSource) || source.rootView == null) {
                continue;
            }//from  w  w  w.j  av  a 2  s.c  o  m
            updateSourceStatusUi(source);
        }
        return;
    }

    // This is a newly selected source.
    boolean selected;
    int index = -1;
    for (final Source source : mSources) {
        ++index;
        if (source.componentName.equals(previousSelectedSource)) {
            selected = false;
        } else if (source.componentName.equals(mSelectedSource)) {
            mSelectedSourceIndex = index;
            selected = true;
        } else {
            continue;
        }

        if (source.rootView == null) {
            continue;
        }

        View sourceImageButton = source.rootView.findViewById(R.id.source_image);
        Drawable drawable = selected ? mSelectedSourceImage : source.icon;
        drawable.setColorFilter(source.color, PorterDuff.Mode.SRC_ATOP);
        sourceImageButton.setBackground(drawable);

        float alpha = selected ? 1f : ALPHA_UNSELECTED;
        source.rootView.animate().alpha(alpha).setDuration(mAnimationDuration);

        if (selected) {
            updateSourceStatusUi(source);
        }

        animateSettingsButton(source.settingsButton, selected && source.settingsActivity != null, allowAnimate);
    }

    if (mSelectedSourceIndex >= 0 && allowAnimate) {
        if (mCurrentScroller != null) {
            mCurrentScroller.cancel();
        }

        // For some reason smoothScrollTo isn't very smooth..
        mCurrentScroller = ObjectAnimator.ofInt(mSourceScrollerView, "scrollX",
                mItemWidth * mSelectedSourceIndex);
        mCurrentScroller.setDuration(mAnimationDuration);
        mCurrentScroller.start();
    }
}

From source file:ca.ualberta.cs.drivr.RequestsListAdapter.java

/**
 * Called when the view holder is wants to bind the request at a certain position in the list.
 * @param viewHolder/*ww w  .  j av  a  2s  . co  m*/
 * @param position
 */
@Override
public void onBindViewHolder(final RequestsListAdapter.ViewHolder viewHolder, final int position) {
    final Request request = requestsToDisplay.get(position);

    // Get the views to update
    final TextView otherUserNameTextView = viewHolder.otherUserNameTextView;
    final TextView descriptionTextView = viewHolder.descriptionTextView;
    final TextView fareTextView = viewHolder.fareTextView;
    final TextView routeTextView = viewHolder.routeTextView;
    final TextView statusTextView = viewHolder.statusTextView;
    final ImageView callImageView = viewHolder.callImageView;
    final ImageView emailImageView = viewHolder.emailImageView;
    final ImageView checkImageView = viewHolder.checkMarkImageView;
    final ImageView deleteImageView = viewHolder.xMarkImageView;

    // Todo Hide Image Views until correct Request State
    if (request.getRequestState() != RequestState.CONFIRMED) {
        checkImageView.setVisibility(View.INVISIBLE);
    }

    if (request.getRequestState() != RequestState.PENDING) {
        deleteImageView.setVisibility(View.INVISIBLE);
    }

    // Show the other person's name
    final DriversList drivers = request.getDrivers();

    // Get the username of the other user
    if (userManager.getUserMode() == UserMode.RIDER) {
        final String multipleDrivers = "Multiple Drivers Accepted";
        final String driverUsername = drivers.size() == 1 ? drivers.get(0).getUsername() : "No Driver Yet";
        otherUserNameTextView.setText(drivers.size() > 1 ? multipleDrivers : driverUsername);
    } else {
        otherUserNameTextView.setText(request.getRider().getUsername());
    }

    // If the request has a description, show it. Otherwise, hide te description
    if (Strings.isNullOrEmpty(request.getDescription()))
        descriptionTextView.setVisibility(View.GONE);
    else
        descriptionTextView.setText(request.getDescription());

    // Show the fare
    fareTextView.setText("$" + request.getFareString());

    // Show the route
    routeTextView.setText(request.getRoute());

    // Driver User
    otherUserNameTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final String otherUsername = otherUserNameTextView.getText().toString();
            // there exists drivers
            if (otherUsername != "No Driver Yet") {
                if (otherUsername != "Multiple Drivers Accepted") {
                    Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create();

                    ElasticSearch elasticSearch = new ElasticSearch(
                            UserManager.getInstance().getConnectivityManager());
                    User user = elasticSearch.loadUser(otherUsername);

                    String driverString = gson.toJson(user, User.class);
                    Intent intent = new Intent(context, DriverProfileActivity.class);
                    intent.putExtra(DriverProfileActivity.DRIVER, driverString);
                    context.startActivity(intent);
                } else {
                    startMultipleDriverIntent(request);
                }
            }
        }
    });

    routeTextView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Gson gson = new GsonBuilder().registerTypeAdapter(Uri.class, new UriSerializer()).create();
            String requestString = gson.toJson(request, Request.class);
            Intent intent = new Intent(context, RequestActivity.class);
            intent.putExtra("UniqueID", "From_RequestListActivity");
            intent.putExtra(RequestActivity.EXTRA_REQUEST, requestString);
            context.startActivity(intent);
        }
    });

    // Show the status text
    statusTextView.setText(request.getRequestState().toString());

    // Add a listener to the call image
    callImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (drivers.size() == 0) {
                Toast.makeText(context, "No driver number available at this time", Toast.LENGTH_SHORT).show();

            }
            // Start Dialer
            else if (drivers.size() == 1) {
                Intent intent = new Intent(Intent.ACTION_CALL);
                String number;
                if (UserManager.getInstance().getUserMode().equals(UserMode.RIDER)) {
                    number = drivers.get(0).getPhoneNumber();
                } else {
                    number = request.getRider().getPhoneNumber();
                }
                number = "tel:" + number;
                intent.setData(Uri.parse(number));
                if (ActivityCompat.checkSelfPermission(context,
                        Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {

                    return;
                }
                context.startActivity(intent);

            } else {

                startMultipleDriverIntent(request);
            }
        }
    });

    // Add a listener to the email image
    emailImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (drivers.size() == 0) {
                Toast.makeText(context, "No driver email available at this time", Toast.LENGTH_SHORT).show();

            }
            //http://stackoverflow.com/questions/8701634/send-email-intent
            else if (drivers.size() == 1) {

                Intent intent = new Intent();
                ComponentName emailApp = intent.resolveActivity(context.getPackageManager());
                ComponentName unsupportedAction = ComponentName
                        .unflattenFromString("com.android.fallback/.Fallback");
                boolean hasEmailApp = emailApp != null && !emailApp.equals(unsupportedAction);
                String email;

                if (UserManager.getInstance().getUserMode().equals(UserMode.RIDER)) {
                    email = drivers.get(0).getEmail();
                } else {
                    email = request.getRider().getEmail();
                }
                String subject = "Drivr Request: " + request.getId();
                String body = "Drivr user " + drivers.get(0).getUsername();

                if (hasEmailApp) {
                    Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.parse("mailto:" + email));
                    emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
                    emailIntent.putExtra(Intent.EXTRA_TEXT, body);
                    context.startActivity(Intent.createChooser(emailIntent, "Chooser Title"));
                } else {
                    Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts("mailto", email, null));
                    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "");
                    emailIntent.putExtra(Intent.EXTRA_TEXT, "");
                    context.startActivity(Intent.createChooser(emailIntent, "Send email..."));
                }
            } else {
                startMultipleDriverIntent(request);

            }
        }
    });

    // Complete The Request
    checkImageView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            Intent intent = new Intent(context, RequestCompletedActivity.class);
            intent.putExtra(RequestCompletedActivity.REQUEST_ID_EXTRA, request.getId());
            context.startActivity(intent);
        }
    });

    deleteImageView.setOnClickListener(new View.OnClickListener() {

        // Todo Delete the Request
        @Override
        public void onClick(View v) {
            v.getContext();
            ElasticSearch elasticSearch = new ElasticSearch(
                    (ConnectivityManager) v.getContext().getSystemService(Context.CONNECTIVITY_SERVICE));
            elasticSearch.deleteRequest(request.getId());
            UserManager userManager = UserManager.getInstance();
            userManager.getRequestsList().removeById(request);
            userManager.notifyObservers();
            requestsToDisplay.remove(request);
            notifyItemRemoved(viewHolder.getAdapterPosition());
        }
    });
}

From source file:com.google.android.apps.muzei.settings.ChooseSourceFragment.java

private void updateSelectedItem(com.google.android.apps.muzei.room.Source selectedSource,
        boolean allowAnimate) {
    ComponentName previousSelectedSource = mSelectedSource;
    if (selectedSource != null) {
        mSelectedSource = selectedSource.componentName;
    }//from w w  w. ja va2 s.  c o m
    if (previousSelectedSource != null && previousSelectedSource.equals(mSelectedSource)) {
        // Only update status
        for (final Source source : mSources) {
            if (!source.componentName.equals(mSelectedSource) || source.rootView == null) {
                continue;
            }
            updateSourceStatusUi(source);
        }
        return;
    }

    // This is a newly selected source.
    boolean selected;
    int index = -1;
    for (final Source source : mSources) {
        ++index;
        if (source.componentName.equals(previousSelectedSource)) {
            selected = false;
        } else if (source.componentName.equals(mSelectedSource)) {
            mSelectedSourceIndex = index;
            selected = true;
        } else {
            continue;
        }

        if (source.rootView == null) {
            continue;
        }

        View sourceImageButton = source.rootView.findViewById(R.id.source_image);
        Drawable drawable = selected ? mSelectedSourceImage : source.icon;
        drawable.setColorFilter(source.color, PorterDuff.Mode.SRC_ATOP);
        sourceImageButton.setBackground(drawable);

        float alpha = selected ? 1f
                : Build.VERSION.SDK_INT >= Build.VERSION_CODES.O
                        && source.targetSdkVersion >= Build.VERSION_CODES.O ? ALPHA_DISABLED : ALPHA_UNSELECTED;
        source.rootView.animate().alpha(alpha).setDuration(mAnimationDuration);

        if (selected) {
            updateSourceStatusUi(source);
        }

        animateSettingsButton(source.settingsButton, selected && source.settingsActivity != null, allowAnimate);
    }

    if (mSelectedSourceIndex >= 0 && allowAnimate) {
        if (mCurrentScroller != null) {
            mCurrentScroller.cancel();
        }

        // For some reason smoothScrollTo isn't very smooth..
        mCurrentScroller = ObjectAnimator.ofInt(mSourceScrollerView, "scrollX",
                mItemWidth * mSelectedSourceIndex);
        mCurrentScroller.setDuration(mAnimationDuration);
        mCurrentScroller.start();
    }
}

From source file:com.android.leanlauncher.LauncherModel.java

private ArrayList<ItemInfo> getItemInfoForComponentName(final ComponentName cname,
        final UserHandleCompat user) {
    ItemInfoFilter filter = new ItemInfoFilter() {
        @Override//from w  w  w.  j a v a 2s .  co m
        public boolean filterItem(ItemInfo parent, ItemInfo info, ComponentName cn) {
            if (info.user == null) {
                return cn.equals(cname);
            } else {
                return cn.equals(cname) && info.user.equals(user);
            }
        }
    };
    return filterItemInfos(sBgItemsIdMap.values(), filter);
}