Android Open Source - AndroidWearable-Samples Background Pickers






From Project

Back to project page AndroidWearable-Samples.

License

The source code is released under:

Apache License

If you think the Android project AndroidWearable-Samples listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.example.android.support.wearable.notifications;
/*w ww  . j  av a 2s  .  c o  m*/
import android.content.Context;
import android.content.res.Resources;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

/**
 * Manages the background image pickers.
 */
public class BackgroundPickers {

    public interface OnBackgroundPickersChangedListener {
        public void onBackgroundPickersChanged(BackgroundPickers pickers);
    }

    private final ViewGroup mContainer;
    private final OnPickedListener mOnPickedListener;
    private final List<ViewGroup> mPickers;
    private final OnBackgroundPickersChangedListener listener;

    public BackgroundPickers(ViewGroup container, OnBackgroundPickersChangedListener listener) {
        this.mContainer = container;
        this.mOnPickedListener = new OnPickedListener();
        this.mPickers = new ArrayList<ViewGroup>();
        this.listener = listener;
    }

    /**
     * Generates the pickers as necessary.
     */
    public void generatePickers(int count) {
        // Clear existing containers.
        clear();

        // Fill in new pickers.
        LayoutInflater inflater = LayoutInflater.from(mContainer.getContext());
        Resources res = mContainer.getResources();
        for (int i = 0; i < count; i++) {
            View picker = inflater.inflate(R.layout.background_picker, mContainer, false);
            TextView label = (TextView) picker.findViewById(R.id.bg_picker_label);
            label.setText(String.format(res.getString(R.string.bg_picker_label), i+1));
            ViewGroup pickerBox = (ViewGroup) picker.findViewById(R.id.bg_picker_container);
            mPickers.add(pickerBox);
            for (int j = 0; j < pickerBox.getChildCount(); j++) {
                ImageView img = (ImageView) pickerBox.getChildAt(j);
                img.setOnClickListener(mOnPickedListener);
            }
            mContainer.addView(picker);
        }
    }

    /**
     * Returns the background resource for the picker at the given index.
     * @param position Index of the background picker.
     * @return Id of the background image resource. null if no image is picked.
     */
    public Integer getRes(int position) {
        String tag = (String) mPickers.get(position).getTag();
        if (tag == null) {
            return null;
        }

        Context context = mContainer.getContext();
        return context.getResources().getIdentifier(tag, "drawable", context.getPackageName());
    }

    /**
     * Returns the all the background resources for the pickers managed by this object. Returns null
     * if no pickers exist.
     */
    public Integer[] getRes() {
        if (mPickers.size() == 0) {
            return null;
        }

        Integer[] res = new Integer[mPickers.size()];
        for (int i = 0; i < mPickers.size(); i++) {
            res[i] = getRes(i);
        }
        return res;
    }

    /**
     * Clears the pickers.
     */
    public void clear() {
        mContainer.removeAllViews();
        mPickers.clear();
    }

    public int getCount() {
        return mPickers.size();
    }

    private class OnPickedListener implements View.OnClickListener {

        @Override
        public void onClick(View view) {
            ImageView pickedView = (ImageView) view;
            ViewGroup pickerBox = (ViewGroup) view.getParent();

            // Clear old selection.
            for (int i = 0; i < pickerBox.getChildCount(); i++) {
                ImageView childView = (ImageView) pickerBox.getChildAt(i);
                childView.setBackgroundResource(R.drawable.unselected_background);
            }

            // Set new selection.
            pickedView.setBackgroundResource(R.drawable.selected_background);
            pickerBox.setTag(pickedView.getTag());

            if (listener != null) {
                listener.onBackgroundPickersChanged(BackgroundPickers.this);
            }
        }
    }
}




Java Source Code List

com.example.android.google.wearable.app.GridExampleActivity.java
com.example.android.google.wearable.app.MainActivity.java
com.example.android.google.wearable.watchviewstub.MainActivity.java
com.example.android.support.wearable.notifications.ActionsPreset.java
com.example.android.support.wearable.notifications.ActionsPresets.java
com.example.android.support.wearable.notifications.AnimatedNotificationDisplayActivity.java
com.example.android.support.wearable.notifications.BackgroundPickers.java
com.example.android.support.wearable.notifications.BasicNotificationDisplayActivity.java
com.example.android.support.wearable.notifications.MainActivity.java
com.example.android.support.wearable.notifications.MainActivity.java
com.example.android.support.wearable.notifications.NamedPreset.java
com.example.android.support.wearable.notifications.NotificationIntentReceiver.java
com.example.android.support.wearable.notifications.NotificationPreset.java
com.example.android.support.wearable.notifications.NotificationPreset.java
com.example.android.support.wearable.notifications.NotificationPresets.java
com.example.android.support.wearable.notifications.NotificationPresets.java
com.example.android.support.wearable.notifications.NotificationUtil.java
com.example.android.support.wearable.notifications.PriorityPreset.java
com.example.android.support.wearable.notifications.PriorityPresets.java
com.example.android.support.wearable.notifications.WearableListItemLayout.java
com.example.android.wearable.agendadata.CalendarQueryService.java
com.example.android.wearable.agendadata.Constants.java
com.example.android.wearable.agendadata.Constants.java
com.example.android.wearable.agendadata.DeleteService.java
com.example.android.wearable.agendadata.HomeListenerService.java
com.example.android.wearable.agendadata.MainActivity.java
com.example.android.wearable.datalayer.DataLayerListenerService.java
com.example.android.wearable.datalayer.MainActivity.java
com.example.android.wearable.datalayer.MainActivity.java
com.example.android.wearable.delayedconfirmation.MainActivity.java
com.example.android.wearable.delayedconfirmation.MainActivity.java
com.example.android.wearable.delayedconfirmation.WearableMessageListenerService.java
com.example.android.wearable.elizachat.ElizaResponder.java
com.example.android.wearable.elizachat.MainActivity.java
com.example.android.wearable.elizachat.ResponderService.java
com.example.android.wearable.embeddedapp.PhoneActivity.java
com.example.android.wearable.embeddedapp.WearableActivity.java
com.example.android.wearable.findphone.DisconnectListenerService.java
com.example.android.wearable.findphone.FindPhoneActivity.java
com.example.android.wearable.findphone.FindPhoneService.java
com.example.android.wearable.findphone.SoundAlarmListenerService.java
com.example.android.wearable.flashlight.MainActivity.java
com.example.android.wearable.flashlight.PartyLightView.java
com.example.android.wearable.geofencing.CheckInAndDeleteDataItemsService.java
com.example.android.wearable.geofencing.Constants.java
com.example.android.wearable.geofencing.Constants.java
com.example.android.wearable.geofencing.GeofenceTransitionsIntentService.java
com.example.android.wearable.geofencing.HomeListenerService.java
com.example.android.wearable.geofencing.MainActivity.java
com.example.android.wearable.geofencing.SimpleGeofenceStore.java
com.example.android.wearable.geofencing.SimpleGeofence.java
com.example.android.wearable.gridviewpager.MainActivity.java
com.example.android.wearable.gridviewpager.SampleGridPagerAdapter.java
com.example.android.wearable.jumpingjack.MainActivity.java
com.example.android.wearable.jumpingjack.PagerAdapter.java
com.example.android.wearable.jumpingjack.Utils.java
com.example.android.wearable.jumpingjack.fragments.CounterFragment.java
com.example.android.wearable.jumpingjack.fragments.SettingsFragment.java
com.example.android.wearable.quiz.Constants.java
com.example.android.wearable.quiz.Constants.java
com.example.android.wearable.quiz.DeleteQuestionService.java
com.example.android.wearable.quiz.JsonUtils.java
com.example.android.wearable.quiz.MainActivity.java
com.example.android.wearable.quiz.QuizListenerService.java
com.example.android.wearable.quiz.QuizReportActionService.java
com.example.android.wearable.quiz.UpdateQuestionService.java
com.example.android.wearable.recipeassistant.AssetUtils.java
com.example.android.wearable.recipeassistant.Constants.java
com.example.android.wearable.recipeassistant.MainActivity.java
com.example.android.wearable.recipeassistant.RecipeActivity.java
com.example.android.wearable.recipeassistant.RecipeListAdapter.java
com.example.android.wearable.recipeassistant.RecipeService.java
com.example.android.wearable.recipeassistant.Recipe.java
com.example.android.wearable.synchronizednotifications.DismissListener.java
com.example.android.wearable.synchronizednotifications.NotificationUpdateService.java
com.example.android.wearable.synchronizednotifications.PhoneActivity.java
com.example.android.wearable.synchronizednotifications.WearableActivity.java
com.example.android.wearable.synchronizednotifications.common.Constants.java
com.example.android.wearable.timer.SetTimerActivity.java
com.example.android.wearable.timer.TimerNotificationService.java
com.example.android.wearable.timer.util.Constants.java
com.example.android.wearable.timer.util.TimerFormat.java
com.example.android.wearable.timer.util.TimerObj.java