Example usage for android.text TextUtils equals

List of usage examples for android.text TextUtils equals

Introduction

In this page you can find the example usage for android.text TextUtils equals.

Prototype

public static boolean equals(CharSequence a, CharSequence b) 

Source Link

Document

Returns true if a and b are equal, including if they are both null.

Usage

From source file:com.google.android.apps.muzei.notifications.NewWallpaperNotificationReceiver.java

public static void maybeShowNewArtworkNotification(Context context) {
    ArtDetailOpenedClosedEvent adoce = EventBus.getDefault().getStickyEvent(ArtDetailOpenedClosedEvent.class);
    if (adoce != null && adoce.isArtDetailOpened()) {
        return;// w  w w .  j  ava  2s.  co  m
    }

    if (!isNewWallpaperNotificationEnabled(context)) {
        return;
    }

    ContentResolver contentResolver = context.getContentResolver();
    ArtworkSource artworkSource = MuzeiDatabase.getInstance(context).artworkDao()
            .getCurrentArtworkWithSourceBlocking();
    if (artworkSource == null) {
        return;
    }

    SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
    long currentArtworkId = artworkSource.artwork.id;
    long lastReadArtworkId = sp.getLong(PREF_LAST_READ_NOTIFICATION_ARTWORK_ID, -1);
    String currentImageUri = artworkSource.artwork.imageUri != null ? artworkSource.artwork.imageUri.toString()
            : null;
    String lastReadImageUri = sp.getString(PREF_LAST_READ_NOTIFICATION_ARTWORK_IMAGE_URI, null);
    String currentToken = artworkSource.artwork.token;
    String lastReadToken = sp.getString(PREF_LAST_READ_NOTIFICATION_ARTWORK_TOKEN, null);
    // We've already dismissed the notification if the IDs match
    boolean previouslyDismissedNotification = lastReadArtworkId == currentArtworkId;
    // We've already dismissed the notification if the image URIs match and both are not empty
    previouslyDismissedNotification = previouslyDismissedNotification || (!TextUtils.isEmpty(lastReadImageUri)
            && !TextUtils.isEmpty(currentImageUri) && TextUtils.equals(lastReadImageUri, currentImageUri));
    // We've already dismissed the notification if the tokens match and both are not empty
    previouslyDismissedNotification = previouslyDismissedNotification || (!TextUtils.isEmpty(lastReadToken)
            && !TextUtils.isEmpty(currentToken) && TextUtils.equals(lastReadToken, currentToken));
    if (previouslyDismissedNotification) {
        return;
    }

    Bitmap largeIcon;
    Bitmap background;
    try {
        BitmapFactory.Options options = new BitmapFactory.Options();
        // Check if there's rotation
        int rotation = 0;
        try (InputStream in = contentResolver.openInputStream(MuzeiContract.Artwork.CONTENT_URI)) {
            if (in == null) {
                return;
            }
            ExifInterface exifInterface = new ExifInterface(in);
            int orientation = exifInterface.getAttributeInt(ExifInterface.TAG_ORIENTATION,
                    ExifInterface.ORIENTATION_NORMAL);
            switch (orientation) {
            case ExifInterface.ORIENTATION_ROTATE_90:
                rotation = 90;
                break;
            case ExifInterface.ORIENTATION_ROTATE_180:
                rotation = 180;
                break;
            case ExifInterface.ORIENTATION_ROTATE_270:
                rotation = 270;
                break;
            }
        } catch (IOException | NumberFormatException | StackOverflowError e) {
            Log.w(TAG, "Couldn't open EXIF interface on artwork", e);
        }
        BitmapRegionLoader regionLoader = BitmapRegionLoader
                .newInstance(contentResolver.openInputStream(MuzeiContract.Artwork.CONTENT_URI), rotation);
        int width = regionLoader.getWidth();
        int height = regionLoader.getHeight();
        int shortestLength = Math.min(width, height);
        options.inJustDecodeBounds = false;
        int largeIconHeight = context.getResources()
                .getDimensionPixelSize(android.R.dimen.notification_large_icon_height);
        options.inSampleSize = ImageUtil.calculateSampleSize(shortestLength, largeIconHeight);
        largeIcon = regionLoader.decodeRegion(new Rect(0, 0, width, height), options);

        // Use the suggested 400x400 for Android Wear background images per
        // http://developer.android.com/training/wearables/notifications/creating.html#AddWearableFeatures
        options.inSampleSize = ImageUtil.calculateSampleSize(height, 400);
        background = regionLoader.decodeRegion(new Rect(0, 0, width, height), options);
    } catch (IOException e) {
        Log.e(TAG, "Unable to load artwork to show notification", e);
        return;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
        createNotificationChannel(context);
    }

    String artworkTitle = artworkSource.artwork.title;
    String title = TextUtils.isEmpty(artworkTitle) ? context.getString(R.string.app_name) : artworkTitle;
    NotificationCompat.Builder nb = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL)
            .setSmallIcon(R.drawable.ic_stat_muzei)
            .setColor(ContextCompat.getColor(context, R.color.notification))
            .setPriority(NotificationCompat.PRIORITY_MIN).setAutoCancel(true).setContentTitle(title)
            .setContentText(context.getString(R.string.notification_new_wallpaper)).setLargeIcon(largeIcon)
            .setContentIntent(PendingIntent.getActivity(context, 0,
                    context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()),
                    PendingIntent.FLAG_UPDATE_CURRENT))
            .setDeleteIntent(PendingIntent.getBroadcast(context, 0,
                    new Intent(context, NewWallpaperNotificationReceiver.class)
                            .setAction(ACTION_MARK_NOTIFICATION_READ),
                    PendingIntent.FLAG_UPDATE_CURRENT));
    NotificationCompat.BigPictureStyle style = new NotificationCompat.BigPictureStyle().bigLargeIcon(null)
            .setBigContentTitle(title).setSummaryText(artworkSource.artwork.byline).bigPicture(background);
    nb.setStyle(style);

    NotificationCompat.WearableExtender extender = new NotificationCompat.WearableExtender();

    // Support Next Artwork
    if (artworkSource.supportsNextArtwork) {
        PendingIntent nextPendingIntent = PendingIntent.getBroadcast(context, 0,
                new Intent(context, NewWallpaperNotificationReceiver.class).setAction(ACTION_NEXT_ARTWORK),
                PendingIntent.FLAG_UPDATE_CURRENT);
        nb.addAction(R.drawable.ic_notif_next_artwork,
                context.getString(R.string.action_next_artwork_condensed), nextPendingIntent);
        // Android Wear uses larger action icons so we build a
        // separate action
        extender.addAction(new NotificationCompat.Action.Builder(R.drawable.ic_notif_full_next_artwork,
                context.getString(R.string.action_next_artwork_condensed), nextPendingIntent)
                        .extend(new NotificationCompat.Action.WearableExtender().setAvailableOffline(false))
                        .build());
    }
    List<UserCommand> commands = artworkSource.commands;
    // Show custom actions as a selectable list on Android Wear devices
    if (!commands.isEmpty()) {
        String[] actions = new String[commands.size()];
        for (int h = 0; h < commands.size(); h++) {
            actions[h] = commands.get(h).getTitle();
        }
        PendingIntent userCommandPendingIntent = PendingIntent.getBroadcast(context, 0,
                new Intent(context, NewWallpaperNotificationReceiver.class).setAction(ACTION_USER_COMMAND),
                PendingIntent.FLAG_UPDATE_CURRENT);
        RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_USER_COMMAND).setAllowFreeFormInput(false)
                .setLabel(context.getString(R.string.action_user_command_prompt)).setChoices(actions).build();
        extender.addAction(new NotificationCompat.Action.Builder(R.drawable.ic_notif_full_user_command,
                context.getString(R.string.action_user_command), userCommandPendingIntent)
                        .addRemoteInput(remoteInput)
                        .extend(new NotificationCompat.Action.WearableExtender().setAvailableOffline(false))
                        .build());
    }
    Intent viewIntent = artworkSource.artwork.viewIntent;
    if (viewIntent != null) {
        viewIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        try {
            PendingIntent nextPendingIntent = PendingIntent.getActivity(context, 0, viewIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);
            nb.addAction(R.drawable.ic_notif_info, context.getString(R.string.action_artwork_info),
                    nextPendingIntent);
            // Android Wear uses larger action icons so we build a
            // separate action
            extender.addAction(new NotificationCompat.Action.Builder(R.drawable.ic_notif_full_info,
                    context.getString(R.string.action_artwork_info), nextPendingIntent)
                            .extend(new NotificationCompat.Action.WearableExtender().setAvailableOffline(false))
                            .build());
        } catch (RuntimeException ignored) {
            // This is actually meant to catch a FileUriExposedException, but you can't
            // have catch statements for exceptions that don't exist at your minSdkVersion
        }
    }
    nb.extend(extender);

    // Hide the image and artwork title for the public version
    NotificationCompat.Builder publicBuilder = new NotificationCompat.Builder(context, NOTIFICATION_CHANNEL)
            .setSmallIcon(R.drawable.ic_stat_muzei)
            .setColor(ContextCompat.getColor(context, R.color.notification))
            .setPriority(NotificationCompat.PRIORITY_MIN).setAutoCancel(true)
            .setContentTitle(context.getString(R.string.app_name))
            .setContentText(context.getString(R.string.notification_new_wallpaper))
            .setContentIntent(PendingIntent.getActivity(context, 0,
                    context.getPackageManager().getLaunchIntentForPackage(context.getPackageName()),
                    PendingIntent.FLAG_UPDATE_CURRENT))
            .setDeleteIntent(PendingIntent.getBroadcast(context, 0,
                    new Intent(context, NewWallpaperNotificationReceiver.class)
                            .setAction(ACTION_MARK_NOTIFICATION_READ),
                    PendingIntent.FLAG_UPDATE_CURRENT));
    nb.setPublicVersion(publicBuilder.build());

    NotificationManagerCompat nm = NotificationManagerCompat.from(context);
    nm.notify(NOTIFICATION_ID, nb.build());
}

From source file:com.clearcenter.mobile_demo.mdAuthenticatorActivity.java

public void handleLogin(View view) {
    if (request_new_account)
        Log.i(TAG, "handleLogin: new account");
    else/*  w  ww .  j a  v  a  2s  . c o  m*/
        Log.i(TAG, "handleLogin: existing account");

    nickname = nickname_edit.getText().toString();
    hostname = hostname_edit.getText().toString();
    username = username_edit.getText().toString();
    password = password_edit.getText().toString();

    final Account accounts[] = account_manager.getAccountsByType(mdConstants.ACCOUNT_TYPE);
    for (Account account : accounts) {
        if (request_new_account && TextUtils.equals(account.name, nickname)) {
            message.setText(getText(R.string.login_activity_duplicate_account));
            scroll_view.smoothScrollTo(0, 0);
            nickname_edit.requestFocus();
            nickname_edit.setSelected(true);
            return;
        }
        Log.i(TAG, account.name + " != " + nickname);
    }

    if (request_new_account) {
        if (TextUtils.isEmpty(nickname)) {
            message.setText(getText(R.string.login_activity_null_nickname));
            scroll_view.smoothScrollTo(0, 0);
            nickname_edit.requestFocus();
            nickname_edit.setSelected(true);
            return;
        }
        if (TextUtils.isEmpty(hostname)) {
            message.setText(getText(R.string.login_activity_null_hostname));
            scroll_view.smoothScrollTo(0, 0);
            hostname_edit.requestFocus();
            hostname_edit.setSelected(true);
            return;
        }
        if (TextUtils.isEmpty(username)) {
            message.setText(getText(R.string.login_activity_null_username));
            scroll_view.smoothScrollTo(0, 0);
            username_edit.requestFocus();
            username_edit.setSelected(true);
            return;
        }
    }
    if (TextUtils.isEmpty(password)) {
        message.setText(getText(R.string.login_activity_null_password));
        scroll_view.smoothScrollTo(0, 0);
        password_edit.requestFocus();
        password_edit.setSelected(true);
        return;
    }
    // Show a progress dialog, and kick off a background task to perform
    // the user login attempt.
    showProgress();
    auth_task = new UserLoginTask();
    auth_task.execute();
}

From source file:com.radiofarda.istgah.playback.CastPlayback.java

private void loadMedia(String mediaId, boolean autoPlay) throws JSONException {
    String musicId = mediaId;/*  w w  w .  j av a 2s  .  c  om*/
    MediaMetadataCompat track = mMusicProvider.getMusic(musicId);
    if (track == null) {
        throw new IllegalArgumentException("Invalid mediaId " + mediaId);
    }
    if (!TextUtils.equals(mediaId, mCurrentMediaId)) {
        mCurrentMediaId = mediaId;
        mCurrentPosition = 0;
    }
    JSONObject customData = new JSONObject();
    customData.put(ITEM_ID, mediaId);
    MediaInfo media = toCastMediaMetadata(track, customData);
    mRemoteMediaClient.load(media, autoPlay, mCurrentPosition, customData);
}

From source file:com.example.android.uamp.utils.QueueHelper.java

/**
 * Determine if queue item matches the currently playing queue item
 *
 * @param context for retrieving the {@link MediaControllerCompat}
 * @param queueItem to compare to currently playing {@link MediaSessionCompat.QueueItem}
 * @return boolean indicating whether queue item matches currently playing queue item
 *///ww w  . j a v a  2  s .  co m
public static boolean isQueueItemPlaying(Context context, MediaSessionCompat.QueueItem queueItem) {
    // Queue item is considered to be playing or paused based on both the controller's
    // current media id and the controller's active queue item id
    MediaControllerCompat controller = ((FragmentActivity) context).getSupportMediaController();
    if (controller != null && controller.getPlaybackState() != null) {
        long currentPlayingQueueId = controller.getPlaybackState().getActiveQueueItemId();
        String currentPlayingMediaId = controller.getMetadata().getDescription().getMediaId();
        String itemMusicId = MediaIDHelper.extractMusicIDFromMediaID(queueItem.getDescription().getMediaId());
        if (queueItem.getQueueId() == currentPlayingQueueId && currentPlayingMediaId != null
                && TextUtils.equals(currentPlayingMediaId, itemMusicId)) {
            return true;
        }
    }
    return false;
}

From source file:com.classiqo.nativeandroid_32bitz.playback.CastPlayback.java

private void setMetadataFromRemote() {
    try {/*w  w w  .  java  2  s  .co  m*/
        MediaInfo mediaInfo = mRemoteMediaClient.getMediaInfo();

        if (mediaInfo == null) {
            return;
        }
        JSONObject customData = mediaInfo.getCustomData();

        if (customData != null && customData.has(ITEM_ID)) {
            String remoteMediaId = customData.getString(ITEM_ID);

            if (!TextUtils.equals(mCurrentMediaId, remoteMediaId)) {
                mCurrentMediaId = remoteMediaId;

                if (mCallback != null) {
                    mCallback.setCurrentMediaId(remoteMediaId);
                }
                updateLastKnownStreamPosition();
            }
        }
    } catch (JSONException e) {
        LogHelper.e(TAG, e, "Exception processing update metadata");
    }
}

From source file:com.murrayc.galaxyzoo.app.SubjectFragment.java

public void update() {
    final Activity activity = getActivity();
    if (activity == null)
        return;/*w ww.j a va 2s. co m*/

    //If the item is the next ID, then wait for the parent (ClassifyFragment) fragment
    //to discover the real ID, after which it will update this fragment with the real ID.
    //Otherwise, we will quickly ask for two next items at almost the same time,
    //resulting in a longer wait for the first item (at first app start) to be ready.
    if (!TextUtils.equals(getItemId(), ItemsContentProvider.URI_PART_ITEM_ID_NEXT)) {
        /*
         * Initializes the CursorLoader. The URL_LOADER value is eventually passed
         * to onCreateLoader().
         * We use restartLoader(), instead of initLoader(),
         * so we can refresh this fragment to show a different subject,
         * even when using the same query ("next") to do that.
         */
        getLoaderManager().restartLoader(URL_LOADER, null, this);
    }
}

From source file:com.kanedias.vanilla.lyrics.LyricsShowActivity.java

/**
 * Handle user-interactive intent after activity was initialized. Loads lyrics from various sources if necessary.
 * @param useLocal true if tag info or *.lrc file can be used to retrieve lyrics, false if only network is allowed
 *///  w  w w  .  j  av a 2 s .  co m
private void handleUiIntent(boolean useLocal) {
    if (useLocal && !TextUtils.isEmpty(mLyricsText.getText())) {
        // we already have lyrics loaded, skip trying to get it from elsewhere
        return;
    }

    // check if this is an answer from tag plugin
    if (useLocal && TextUtils.equals(getIntent().getStringExtra(EXTRA_PARAM_P2P), P2P_READ_TAG)) {
        String[] fields = getIntent().getStringArrayExtra(EXTRA_PARAM_P2P_VAL);
        if (fields != null && fields.length > 0 && !TextUtils.isEmpty(fields[0])) {
            // start activity with retrieved lyrics
            String lyrics = getIntent().getStringArrayExtra(EXTRA_PARAM_P2P_VAL)[0];
            showFetchedLyrics(lyrics);
            return;
        }
    }

    // try to load from *.lrc file nearby
    if (useLocal && loadFromFile()) {
        return;
    }

    // we didn't receive lyrics from tag plugin, try to retrieve it via lyrics engine
    new LyricsFetcher().execute(getIntent());
}

From source file:com.agateau.equiv.ui.MealItemDetailActivity.java

@Override
public void onRestoreInstanceState(@NonNull Bundle bundle) {
    super.onRestoreInstanceState(bundle);
    String productUuid = bundle.getString("productUuid", "");
    if (!TextUtils.equals(productUuid, "")) {
        Product product = mProductStore.findByUuid(UUID.fromString(productUuid));
        onSelectProduct(product);//w  w w  .  ja v  a  2s. co  m
        mQuantityEquivEdit.setText(bundle.getString("quantityEquiv"));
    }
}

From source file:com.nicolls.ablum.activity.BucketHomeFragmentActivity.java

@SuppressLint("ResourceAsColor")
@Override/*from w w w.ja  v a2  s . c om*/
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.activity_home_media_chooser);
    mediaType = getIntent().getStringExtra("mediaType");
    List<String> pathList = getIntent().getStringArrayListExtra("pathList");

    headerBarTitle = (TextView) findViewById(R.id.titleTextViewFromMediaChooserHeaderBar);
    headerBarCamera = (ImageView) findViewById(R.id.cameraImageViewFromMediaChooserHeaderBar);
    headerBarBack = (ImageView) findViewById(R.id.backArrowImageViewFromMediaChooserHeaderView);
    headerBarDone = (TextView) findViewById(R.id.doneTextViewViewFromMediaChooserHeaderView);
    mTabHost = (FragmentTabHost) findViewById(android.R.id.tabhost);

    headerBarBack.setOnClickListener(clickListener);
    headerBarCamera.setOnClickListener(clickListener);
    headerBarDone.setOnClickListener(clickListener);

    headerBarDone.setVisibility(View.INVISIBLE);

    mTabHost.setup(this, getSupportFragmentManager(), R.id.realTabcontent);
    mTabHost.addTab(
            mTabHost.newTabSpec("tab1").setIndicator(getResources().getString(R.string.images_tab) + "      "),
            BucketImageFragment.class, null);
    mTabHost.addTab(
            mTabHost.newTabSpec("tab2").setIndicator(getResources().getString(R.string.videos_tab) + "      "),
            BucketVideoFragment.class, null);

    mTabHost.getTabWidget().setBackgroundColor(getResources().getColor(R.color.tabs_color));

    for (int i = 0; i < mTabHost.getTabWidget().getChildCount(); i++) {

        View childView = mTabHost.getTabWidget().getChildAt(i);
        TextView textView = (TextView) childView.findViewById(android.R.id.title);

        if (textView.getLayoutParams() instanceof RelativeLayout.LayoutParams) {

            RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) textView.getLayoutParams();
            params.addRule(RelativeLayout.CENTER_HORIZONTAL);
            params.addRule(RelativeLayout.CENTER_VERTICAL);
            params.height = RelativeLayout.LayoutParams.MATCH_PARENT;
            params.width = RelativeLayout.LayoutParams.WRAP_CONTENT;
            textView.setLayoutParams(params);

        } else if (textView.getLayoutParams() instanceof LinearLayout.LayoutParams) {
            LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) textView.getLayoutParams();
            params.gravity = Gravity.CENTER;
            textView.setLayoutParams(params);
        }
        textView.setTextColor(getResources().getColor(R.color.tabs_title_color));
        textView.setTextSize(convertDipToPixels(10));
    }

    ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title)))
            .setTextColor(getResources().getColor(R.color.headerbar_selected_tab_color));
    ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title)))
            .setTextColor(Color.WHITE);

    mTabHost.setOnTabChangedListener(new OnTabChangeListener() {

        @Override
        public void onTabChanged(String tabId) {
            //            Toast.makeText(getApplicationContext(),tabId,Toast.LENGTH_LONG).show();
            android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
            BucketImageFragment imageFragment = (BucketImageFragment) fragmentManager.findFragmentByTag("tab1");
            BucketVideoFragment videoFragment = (BucketVideoFragment) fragmentManager.findFragmentByTag("tab2");
            android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();

            if (tabId.equalsIgnoreCase("tab1")) {

                headerBarTitle.setText(getResources().getString(R.string.image));
                headerBarCamera.setBackgroundResource(R.drawable.selector_camera_button);
                headerBarCamera.setTag(getResources().getString(R.string.image));

                if (imageFragment == null) {
                    BucketImageFragment newImageFragment = new BucketImageFragment();
                    fragmentTransaction.add(R.id.realTabcontent, newImageFragment, "tab1");

                } else {

                    if (videoFragment != null) {
                        fragmentTransaction.hide(videoFragment);
                    }

                    fragmentTransaction.show(imageFragment);

                }
                ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title)))
                        .setTextColor(getResources().getColor(R.color.headerbar_selected_tab_color));
                ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title)))
                        .setTextColor(Color.WHITE);

            } else {
                headerBarTitle.setText(getResources().getString(R.string.video));
                headerBarCamera.setBackgroundResource(R.drawable.selector_video_button);
                headerBarCamera.setTag(getResources().getString(R.string.video));

                if (videoFragment == null) {

                    final BucketVideoFragment newVideoFragment = new BucketVideoFragment();
                    fragmentTransaction.add(R.id.realTabcontent, newVideoFragment, "tab2");

                } else {

                    if (imageFragment != null) {
                        fragmentTransaction.hide(imageFragment);
                    }

                    fragmentTransaction.show(videoFragment);
                }

                ((TextView) (mTabHost.getTabWidget().getChildAt(0).findViewById(android.R.id.title)))
                        .setTextColor(Color.WHITE);
                ((TextView) (mTabHost.getTabWidget().getChildAt(1).findViewById(android.R.id.title)))
                        .setTextColor(getResources().getColor(R.color.headerbar_selected_tab_color));

            }

            fragmentTransaction.commit();
        }
    });

    RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) headerBarCamera.getLayoutParams();
    params.height = convertDipToPixels(40);
    params.width = convertDipToPixels(40);
    headerBarCamera.setLayoutParams(params);
    headerBarCamera.setScaleType(ScaleType.CENTER_INSIDE);
    headerBarCamera.setPadding(convertDipToPixels(15), convertDipToPixels(15), convertDipToPixels(15),
            convertDipToPixels(15));

    if (TextUtils.equals(mediaType, MediaChooserConstants.TYPE_PHOTO)) {//?
        mTabHost.setCurrentTab(0);
        headerBarTitle.setText(getResources().getString(R.string.image));
        headerBarCamera.setTag(getResources().getString(R.string.image));
        headerBarCamera.setBackgroundResource(R.drawable.selector_camera_button);
    } else {
        mTabHost.setCurrentTab(1);
        headerBarTitle.setText(getResources().getString(R.string.video));
        headerBarCamera.setTag(getResources().getString(R.string.video));
        headerBarCamera.setBackgroundResource(R.drawable.selector_video_button);
    }
}

From source file:com.justwayward.reader.ui.activity.SearchActivity.java

/**
 * ??.????20?/*ww w.jav  a  2 s.com*/
 *
 * @param query
 */
private void saveSearchHistory(String query) {
    List<String> list = CacheManager.getInstance().getSearchHistory();
    if (list == null) {
        list = new ArrayList<>();
        list.add(query);
    } else {
        Iterator<String> iterator = list.iterator();
        while (iterator.hasNext()) {
            String item = iterator.next();
            if (TextUtils.equals(query, item)) {
                iterator.remove();
            }
        }
        list.add(0, query);
    }
    int size = list.size();
    if (size > 20) { // ?20?
        for (int i = size - 1; i >= 20; i--) {
            list.remove(i);
        }
    }
    CacheManager.getInstance().saveSearchHistory(list);
    initSearchHistory();
}