Java Code Examples for android.os.Bundle#getIntArray()

The following examples show how to use android.os.Bundle#getIntArray() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: Swiftnotes   File: ColorPickerDialog.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getArguments() != null) {
        mTitleResId = getArguments().getInt(KEY_TITLE_ID);
        mColumns = getArguments().getInt(KEY_COLUMNS);
        mSize = getArguments().getInt(KEY_SIZE);
    }

    if (savedInstanceState != null) {
        mColors = savedInstanceState.getIntArray(KEY_COLORS);
        mSelectedColor = (Integer) savedInstanceState.getSerializable(KEY_SELECTED_COLOR);
        mColorContentDescriptions = savedInstanceState.getStringArray(
                KEY_COLOR_CONTENT_DESCRIPTIONS);
    }
}
 
Example 2
Source Project: candybar   File: InAppBillingFragment.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    if (savedInstanceState != null) {
        mType = savedInstanceState.getInt(TYPE);
        mKey = savedInstanceState.getString(KEY);
        mProductsId = savedInstanceState.getStringArray(PRODUCT_ID);
        mProductsCount = savedInstanceState.getIntArray(PRODUCT_COUNT);
    }

    mAsyncTask = new InAppProductsLoader().execute();
}
 
Example 3
Source Project: Lay-s   File: PLAAbsListView.java    License: MIT License 5 votes vote down vote up
@Override
public void onRestoreInstanceState(Parcelable state) {
    if (state instanceof  Bundle) {
        Bundle bundle = (Bundle) state;
        mDataChanged = true;
        mSyncHeight = bundle.getInt("height");
        long firstId = bundle.getLong("firstId");
        if (firstId >= 0) {
            mNeedSync = true;
            SavedState ss = new SavedState();
            ss.firstId = firstId;
            ss.height = (int) mSyncHeight;
            ss.position = bundle.getInt("position");
            ss.viewTop = bundle.getInt("viewTop");
            ss.childCount = bundle.getInt("childCount");
            ss.viewTops = bundle.getIntArray("viewTops");
            mPendingSync = ss;
            mSyncRowId = ss.firstId;
            mSyncPosition = ss.position;
            mSpecificTop = ss.viewTop;
            mSpecificTops = ss.viewTops;
        }
        state = bundle.getParcelable("instanceState");
    }
    super.onRestoreInstanceState(state);
    requestLayout();
}
 
Example 4
Source Project: SimplifyReader   File: PLAAbsListView.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void onRestoreInstanceState(Parcelable state) {
    if (state instanceof  Bundle) {
        Bundle bundle = (Bundle) state;
        mDataChanged = true;
        mSyncHeight = bundle.getInt("height");
        long firstId = bundle.getLong("firstId");
        if (firstId >= 0) {
            mNeedSync = true;
            SavedState ss = new SavedState();
            ss.firstId = firstId;
            ss.height = (int) mSyncHeight;
            ss.position = bundle.getInt("position");
            ss.viewTop = bundle.getInt("viewTop");
            ss.childCount = bundle.getInt("childCount");
            ss.viewTops = bundle.getIntArray("viewTops");
            mPendingSync = ss;
            mSyncRowId = ss.firstId;
            mSyncPosition = ss.position;
            mSpecificTop = ss.viewTop;
            mSpecificTops = ss.viewTops;
        }
        state = bundle.getParcelable("instanceState");
    }
    super.onRestoreInstanceState(state);
    requestLayout();
}
 
Example 5
Source Project: Tweetin   File: ColorPickerDialog.java    License: Apache License 2.0 5 votes vote down vote up
public void onCreate(Bundle bundle) {
	super.onCreate(bundle);
	if (getArguments() != null) {
		this.mTitleResId = getArguments().getInt("title_id");
		this.mColumns = getArguments().getInt("columns");
		this.mSize = getArguments().getInt("size");
	}
	if (bundle != null) {
		this.mColors = bundle.getIntArray("colors");
		this.mSelectedColor = ((Integer) bundle.getSerializable("selected_color")).intValue();
	}
}
 
Example 6
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    if (getArguments() != null) {
        mTitleResId = getArguments().getInt(KEY_TITLE_ID);
        mColumns = getArguments().getInt(KEY_COLUMNS);
        mSize = getArguments().getInt(KEY_SIZE);
    }

    if (savedInstanceState != null) {
        mColors = savedInstanceState.getIntArray(KEY_COLORS);
        mSelectedColor = (Integer) savedInstanceState.getSerializable(KEY_SELECTED_COLOR);
    }
}
 
Example 7
@Override
public void onCreate(Bundle savedInstanceState) {
	super.onCreate(savedInstanceState);

	Bundle args = getArguments();
	mItems = args.getStringArray(PHRASES);
	mPhraseIds = args.getIntArray(PHRASE_IDS);
	mActivationWord = args.getString(HOTWORD);
}
 
Example 8
@Override
public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Bundle arguments = getArguments();
    if (arguments != null) {
        mXmlResIdsCount = arguments.getInt(XML_RESIDS_COUNT);
        mXmlResIds = arguments.getIntArray(XML_RESIDS);
        if (mXmlResIdsCount > 0) {
            for (int i = 0; i < mXmlResIdsCount; i++) {
                addPreferencesFromResource(mXmlResIds[i]);
            }
        }
    }
}
 
Example 9
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View v = inflater.inflate(R.layout.fragment_weather_forecast_city_overview, container, false);

    recyclerView = (RecyclerView) v.findViewById(R.id.weatherForecastRecyclerView);
    recyclerView.setLayoutManager(getLayoutManager(getContext()));

    Bundle args = getArguments();
    mCityId = args.getInt("city_id");
    mDataSetTypes = args.getIntArray("dataSetTypes");

    loadData();

    return v;
}
 
Example 10
Source Project: AnimCubeAndroid   File: AnimCube.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * <p>
 * Restores a previously saved state.
 * </p>
 * <p>
 * If the cube was animating when its state was saved, then this method will also resume the animation and repeat the step
 * that was interrupted by the configuration change.
 * </p>
 *
 * @param state a {@link Bundle} containing a previously saved state of the cube.
 * @see #saveState()
 */
public void restoreState(Bundle state) {
    synchronized (animThreadLock) {
        for (int i = 0; i < cube.length; i++) {
            cube[i] = state.getIntArray(CubeState.KEY_CUBE + i);
        }
        for (int i = 0; i < initialCube.length; i++) {
            initialCube[i] = state.getIntArray(CubeState.KEY_INITIAL_CUBE + i);
        }

        move = state.getIntArray(CubeState.KEY_MOVE);
        movePos = state.getInt(CubeState.KEY_MOVE_POS);
        originalAngle = state.getDouble(CubeState.KEY_ORIGINAL_ANGLE);

        double[] buffer = state.getDoubleArray(CubeState.KEY_EYE);
        System.arraycopy(buffer, 0, eye, 0, eye.length);
        buffer = state.getDoubleArray(CubeState.KEY_EYE_X);
        System.arraycopy(buffer, 0, eyeX, 0, eyeX.length);
        buffer = state.getDoubleArray(CubeState.KEY_EYE_Y);
        System.arraycopy(buffer, 0, eyeY, 0, eyeY.length);

        editable = state.getBoolean(CubeState.KEY_EDITABLE);
        backFacesDistance = state.getInt(CubeState.KEY_BACKFACES_DISTANCE);
        setBackFacesDistanceInternal(backFacesDistance);
        speed = state.getInt(CubeState.KEY_SINGLE_ROTATION_SPEED);
        doubleSpeed = state.getInt(CubeState.KEY_DOUBLE_ROTATION_SPEED);
        isDebuggable = state.getBoolean(CubeState.KEY_IS_DEBUGGABLE);

        repaint();
        boolean animating = state.getBoolean(CubeState.KEY_IS_ANIMATING);
        if (animating) {
            int animationMode = state.getInt(CubeState.KEY_ANIMATION_MODE);
            if (animationMode != AnimationMode.STOPPED) {
                startAnimation(animationMode);
            }
        }
    }
}
 
Example 11
/**
 * Load alarm repetition from bundle.
 * @param bundle saved state
 */
protected void loadSettings(Bundle bundle)
{
    int[] colors = bundle.getIntArray(KEY_COLORS);
    if (colors != null) {
        colorOverrides = colors;
    }
    setRepetition( bundle.getBoolean(PREF_KEY_ALARM_REPEAT, PREF_DEF_ALARM_REPEAT),
                   bundle.getIntegerArrayList(PREF_KEY_ALARM_REPEATDAYS) );
}
 
Example 12
private void setUpCharts(Bundle savedInstanceState) {

        if (savedInstanceState != null) {


            powerChart.setChartLength(savedInstanceState.getInt("power_graph_length", -6));
            powerNowWatts = savedInstanceState.getDouble("power_now", 0);
            powerTodaykWh = savedInstanceState.getDouble("power_today", 0);

            int[] chart2_colors = savedInstanceState.getIntArray("chart2_colors");

            updateTextFields();

            //put stored data back in the charts

            int lastPowerFeedId = savedInstanceState.getInt("power_feed_id");
            if (lastPowerFeedId > 0 && lastPowerFeedId == myElectricSettings.getPowerFeedId()) {
                ArrayList<String> chartLabels = savedInstanceState.getStringArrayList("chart1_labels");
                double saved_chart1_values[] = savedInstanceState.getDoubleArray("chart1_values");
                powerChart.restoreData(chartLabels, saved_chart1_values);
            }

            int lastUseFeedId = savedInstanceState.getInt("use_feed_id");
            if (lastUseFeedId > 0 && lastUseFeedId == myElectricSettings.getUseFeedId()) {
                double saved_chart2_values[] = savedInstanceState.getDoubleArray("chart2_values");
                ArrayList<String> chart2Labels = savedInstanceState.getStringArrayList("chart2_labels");
                dailyUsageBarChart.restoreData(chart2Labels, saved_chart2_values, chart2_colors, daysToDisplay);
            }
        }

    }
 
Example 13
Source Project: delion   File: IntentUtils.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Just like {@link Bundle#getIntArray(String)} but doesn't throw exceptions.
 */
public static int[] safeGetIntArray(Bundle bundle, String name) {
    try {
        return bundle.getIntArray(name);
    } catch (Throwable t) {
        // Catches un-parceling exceptions.
        Log.e(TAG, "getIntArray failed on bundle " + bundle);
        return null;
    }
}
 
Example 14
Source Project: DanDanPlayForAndroid   File: LabelsView.java    License: MIT License 4 votes vote down vote up
@Override
    protected void onRestoreInstanceState(Parcelable state) {
        if (state instanceof Bundle) {
            Bundle bundle = (Bundle) state;
            //恢复父类信息
            super.onRestoreInstanceState(bundle.getParcelable(KEY_SUPER_STATE));

            //恢复标签文字颜色
            ColorStateList color = bundle.getParcelable(KEY_TEXT_COLOR_STATE);
            if (color != null) {
                setLabelTextColor(color);
            }
            //恢复标签文字大小
            setLabelTextSize(bundle.getFloat(KEY_TEXT_SIZE_STATE, mTextSize));
//            //恢复标签背景  (由于背景改用Drawable,所以不能自动保存和恢复)
//            int resId = bundle.getInt(KEY_BG_RES_ID_STATE, mLabelBgResId);
//            if (resId != 0) {
//                setLabelBackgroundResource(resId);
//            }
            //恢复标签内边距
            int[] padding = bundle.getIntArray(KEY_PADDING_STATE);
            if (padding != null && padding.length == 4) {
                setLabelTextPadding(padding[0], padding[1], padding[2], padding[3]);
            }
            //恢复标签间隔
            setWordMargin(bundle.getInt(KEY_WORD_MARGIN_STATE, mWordMargin));
            //恢复行间隔
            setLineMargin(bundle.getInt(KEY_LINE_MARGIN_STATE, mLineMargin));
            //恢复标签的选择类型
            setSelectType(SelectType.get(bundle.getInt(KEY_SELECT_TYPE_STATE, mSelectType.value)));
            //恢复标签的最大选择数量
            setMaxSelect(bundle.getInt(KEY_MAX_SELECT_STATE, mMaxSelect));
            //恢复标签的最少选择数量
            setMinSelect(bundle.getInt(KEY_MIN_SELECT_STATE, mMinSelect));
            //恢复标签的最大行数
            setMaxLines(bundle.getInt(KEY_MAX_LINES_STATE, mMaxLines));
            //恢复是否是指示器模式
            setIndicator(bundle.getBoolean(KEY_INDICATOR_STATE, isIndicator));

//            //恢复标签列表
//            ArrayList<String> labels = bundle.getStringArrayList(KEY_LABELS_STATE);
//            if (labels != null && !labels.isEmpty()) {
//                setLabels(labels);
//            }
            //恢复必选项列表
            ArrayList<Integer> compulsory = bundle.getIntegerArrayList(KEY_COMPULSORY_LABELS_STATE);
            if (compulsory != null && !compulsory.isEmpty()) {
                setCompulsorys(compulsory);
            }
            //恢复已选择的标签列表
            ArrayList<Integer> selectLabel = bundle.getIntegerArrayList(KEY_SELECT_LABELS_STATE);
            if (selectLabel != null && !selectLabel.isEmpty()) {
                int size = selectLabel.size();
                int[] positions = new int[size];
                for (int i = 0; i < size; i++) {
                    positions[i] = selectLabel.get(i);
                }
                setSelects(positions);
            }
            return;
        }
        super.onRestoreInstanceState(state);
    }
 
Example 15
Source Project: vlayout   File: StaggeredGridLayoutHelper.java    License: MIT License 4 votes vote down vote up
@Override
public void onRestoreInstanceState(Bundle bundle) {
    super.onRestoreInstanceState(bundle);
    mLazySpanLookup.mData = bundle.getIntArray(LOOKUP_BUNDLE_KEY);
}
 
Example 16
@Override
protected void onRestoreInstanceState(Parcelable state) {

	if (!(state instanceof Bundle)) {
		// Not supposed to happen.
		super.onRestoreInstanceState(state);
		return;
	}

	Bundle b = (Bundle) state;
	Parcelable superState = b.getParcelable("gv_super_state");

	setEnabled(b.getBoolean("gv_en", true));

	int[] data = b.getIntArray("gv_data");
	if (data != null && data.length == mData.length) {
		for (int i = 0; i < data.length; i++) {
			mData[i] = State.fromInt(data[i]);
		}
	}

	mSelectedCell = b.getInt("gv_sel_cell", -1);
	mSelectedValue = State.fromInt(b.getInt("gv_sel_val", State.EMPTY.getValue()));
	mCurrentPlayer = State.fromInt(b.getInt("gv_curr_play", State.EMPTY.getValue()));
	mWinner = State.fromInt(b.getInt("gv_winner", State.EMPTY.getValue()));

	mWinCol = b.getInt("gv_win_col", -1);
	mWinRow = b.getInt("gv_win_row", -1);
	mWinDiag = b.getInt("gv_win_diag", -1);

	mBlinkDisplayOff = b.getBoolean("gv_blink_off", false);
	Rect r = b.getParcelable("gv_blink_rect");
	if (r != null) {
		mBlinkRect.set(r);
	}

	// let the blink handler decide if it should blink or not
	mHandler.sendEmptyMessage(MSG_BLINK);

	super.onRestoreInstanceState(superState);
}
 
Example 17
@Override
public final void restoreInstanceState(@Nullable final Bundle savedInstanceState) {
    if (savedInstanceState != null) {
        referenceTabIndex = savedInstanceState.getInt(REFERENCE_TAB_INDEX_EXTRA, -1);
        referenceTabPosition = savedInstanceState.getFloat(REFERENCE_TAB_POSITION_EXTRA, -1);
        logLevel = (LogLevel) savedInstanceState.getSerializable(LOG_LEVEL_EXTRA);
        tabs = savedInstanceState.getParcelableArrayList(TABS_EXTRA);
        switcherShown = savedInstanceState.getBoolean(SWITCHER_SHOWN_EXTRA);
        int selectedTabIndex = savedInstanceState.getInt(SELECTED_TAB_INDEX_EXTRA);
        selectedTab = selectedTabIndex != -1 ? tabs.get(selectedTabIndex) : null;
        padding = savedInstanceState.getIntArray(PADDING_EXTRA);
        applyPaddingToTabs = savedInstanceState.getBoolean(APPLY_PADDING_TO_TABS_EXTRA);
        tabIconId = savedInstanceState.getInt(TAB_ICON_ID_EXTRA);
        tabIconBitmap = savedInstanceState.getParcelable(TAB_ICON_BITMAP_EXTRA);
        tabIconTintList = savedInstanceState.getParcelable(TAB_ICON_TINT_LIST_EXTRA);
        tabIconTintMode =
                (PorterDuff.Mode) savedInstanceState.getSerializable(TAB_ICON_TINT_MODE_EXTRA);
        tabBackgroundColor = savedInstanceState.getParcelable(TAB_BACKGROUND_COLOR_EXTRA);
        tabContentBackgroundColor =
                savedInstanceState.getInt(TAB_CONTENT_BACKGROUND_COLOR_EXTRA);
        tabTitleTextColor = savedInstanceState.getParcelable(TAB_TITLE_TEXT_COLOR_EXTRA);
        tabCloseButtonIconId = savedInstanceState.getInt(TAB_CLOSE_BUTTON_ICON_ID_EXTRA);
        tabCloseButtonIconBitmap =
                savedInstanceState.getParcelable(TAB_CLOSE_BUTTON_ICON_BITMAP_EXTRA);
        tabCloseButtonIconTintList =
                savedInstanceState.getParcelable(TAB_CLOSE_BUTTON_ICON_TINT_LIST_EXTRA);
        tabCloseButtonIconTintMode = (PorterDuff.Mode) savedInstanceState
                .getSerializable(TAB_CLOSE_BUTTON_ICON_TINT_MODE_EXTRA);
        tabProgressBarColor = savedInstanceState.getInt(TAB_PROGRESS_BAR_COLOR_EXTRA, -1);
        showToolbars = savedInstanceState.getBoolean(SHOW_TOOLBARS_EXTRA);
        toolbarTitle = savedInstanceState.getCharSequence(TOOLBAR_TITLE_EXTRA);
        toolbarNavigationIconTintList =
                savedInstanceState.getParcelable(TOOLBAR_NAVIGATION_ICON_TINT_LIST_EXTRA);
        toolbarNavigationIconTintMode = (PorterDuff.Mode) savedInstanceState
                .getSerializable(TOOLBAR_NAVIGATION_ICON_TINT_MODE_EXTRA);
        tabPreviewFadeThreshold = savedInstanceState.getLong(TAB_PREVIEW_FADE_THRESHOLD_EXTRA);
        tabPreviewFadeDuration = savedInstanceState.getLong(TAB_PREVIEW_FADE_DURATION);
        clearSavedStatesWhenRemovingTabs =
                savedInstanceState.getBoolean(CLEAR_SAVED_STATES_WHEN_REMOVING_TABS_EXTRA);
        getContentRecyclerAdapter().restoreInstanceState(savedInstanceState);
    }
}
 
Example 18
/**
 * OpenAPIParser#parse(String) に testEnum.json を渡して解析を行う。
 * 
 * parameter の type と異なる enum の宣言が存在する testEnum.json をよみこむ。
 * <pre>
 * 【期待する動作】
 * ・Swagger オブジェクトが取得できること。
 * ・parameter の enum が取得できること。
 * </pre>
 */
@Test
public void testEnum() throws JSONException {
    DevicePluginContext pluginContext = Mockito.mock(DevicePluginContext.class);

    String jsonString = FileLoader.readString("parser/testEnum.json");

    DConnectServiceSpec spec = new DConnectServiceSpec(pluginContext);
    spec.addProfileSpec("testEnum", jsonString);

    Bundle swagger = spec.findProfileSpec("testEnum").toBundle();
    assertThat(swagger, is(notNullValue()));

    Bundle paths = swagger.getBundle("paths");
    assertThat(paths, is(notNullValue()));
    assertThat(paths.size(), is(1));

    Bundle a0 = paths.getBundle("/a0");
    assertThat(a0, is(notNullValue()));

    Bundle a0Get = a0.getBundle("get");
    assertThat(a0Get, is(notNullValue()));

    Parcelable[] parameters = a0Get.getParcelableArray("parameters");
    assertThat(parameters, is(notNullValue()));
    assertThat(parameters.length, is(7));

    Bundle stringInt = (Bundle) parameters[1];
    assertThat(stringInt.getString("type"), is("string"));
    String[] stringIntEnum = stringInt.getStringArray("enum");
    assertThat(stringIntEnum, is(notNullValue()));
    assertThat(stringIntEnum[0], is("1"));
    assertThat(stringIntEnum[1], is("2"));
    assertThat(stringIntEnum[2], is("3"));
    assertThat(stringIntEnum[3], is("4"));

    Bundle stringNumber = (Bundle) parameters[2];
    assertThat(stringNumber.getString("type"), is("string"));
    String[] stringNumberEnum = stringNumber.getStringArray("enum");
    assertThat(stringNumberEnum, is(notNullValue()));
    assertThat(stringNumberEnum[0], is("1.1"));
    assertThat(stringNumberEnum[1], is("2.2"));
    assertThat(stringNumberEnum[2], is("3.3"));
    assertThat(stringNumberEnum[3], is("4.4"));

    Bundle intString = (Bundle) parameters[3];
    assertThat(intString.getString("type"), is("integer"));
    assertThat(intString.getString("format"), is("int32"));
    int[] intStringEnum = intString.getIntArray("enum");
    assertThat(intStringEnum, is(notNullValue()));
    assertThat(intStringEnum[0], is(1));
    assertThat(intStringEnum[1], is(2));
    assertThat(intStringEnum[2], is(3));
    assertThat(intStringEnum[3], is(4));

    Bundle longString = (Bundle) parameters[4];
    assertThat(longString.getString("type"), is("integer"));
    assertThat(longString.getString("format"), is("int64"));
    long[] longStringEnum = longString.getLongArray("enum");
    assertThat(longStringEnum, is(notNullValue()));
    assertThat(longStringEnum[0], is(1L));
    assertThat(longStringEnum[1], is(2L));
    assertThat(longStringEnum[2], is(3L));
    assertThat(longStringEnum[3], is(4L));

    Bundle floatString = (Bundle) parameters[5];
    assertThat(floatString.getString("type"), is("number"));
    assertThat(floatString.getString("format"), is("float"));
    float[] floatStringEnum = floatString.getFloatArray("enum");
    assertThat(floatStringEnum, is(notNullValue()));
    assertThat(floatStringEnum[0], is(1.1F));
    assertThat(floatStringEnum[1], is(2.2F));
    assertThat(floatStringEnum[2], is(3.3F));
    assertThat(floatStringEnum[3], is(4.4F));

    Bundle doubleString = (Bundle) parameters[6];
    assertThat(doubleString.getString("type"), is("number"));
    assertThat(doubleString.getString("format"), is("double"));
    double[] doubleStringEnum = doubleString.getDoubleArray("enum");
    assertThat(doubleStringEnum, is(notNullValue()));
    assertThat(doubleStringEnum[0], is(1.1D));
    assertThat(doubleStringEnum[1], is(2.2D));
    assertThat(doubleStringEnum[2], is(3.3D));
    assertThat(doubleStringEnum[3], is(4.4D));
}
 
Example 19
/**
 * @param context the context
 * @param intent the intent that was received
 */
@Override
public void onReceive(@NonNull Context context, @NonNull Intent intent)
{
    super.onReceive(context, intent);
    initLocale(context);

    String filter = getUpdateIntentFilter();
    String action = intent.getAction();
    Bundle extras = intent.getExtras();

    if (action != null && action.equals(filter))
    {
        String widgetClass = intent.getStringExtra(KEY_WIDGETCLASS);
        if (getClass().toString().equals(widgetClass))
        {
            int appWidgetID = intent.getIntExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, -1);  // synonymous
            Log.d(TAG, "onReceive: " + filter + "(" + appWidgetID + "): " + getClass().toString());

            if (appWidgetID <= 0) {
                updateWidgets(context);
            } else {
                onUpdate(context, AppWidgetManager.getInstance(context), new int[]{appWidgetID});
            }
            setUpdateAlarm(context, appWidgetID);      // schedule next update
        }

    } else if (isClickAction(action)) {
        Log.d(TAG, "onReceive: ClickAction :: " + action + ":" + getClass());
        handleClickAction(context, intent);

    } else if (action != null && action.equals(AppWidgetManager.ACTION_APPWIDGET_OPTIONS_CHANGED)) {
        Log.d(TAG, "onReceive: ACTION_APPWIDGET_OPTIONS_CHANGED :: " + getClass());

    } else if (action != null && action.equals(SUNTIMES_THEME_UPDATE)) {
        String themeName = (intent.hasExtra(KEY_THEME) ? intent.getStringExtra(KEY_THEME) : null);
        Log.d(TAG, "onReceive: SUNTIMES_THEME_UPDATE :: " + getClass() + " :: " + themeName);
        updateWidgets(context, themeName);

    } else if (action != null && action.equals(SUNTIMES_ALARM_UPDATE)) {
        Log.d(TAG, "onReceive: SUNTIMES_ALARM_UPDATE :: " + getClass());
        updateWidgets(context);
        setUpdateAlarms(context);

    } else if (action != null && action.equals("android.intent.action.TIME_SET")) {
        Log.d(TAG, "onReceive: android.intent.action.TIME_SET :: " + getClass());
        //updateWidgets(context);
        //setUpdateAlarms(context);
        // TODO: handle TIME_SET better .. when automatic/network time is enabled this thing fires /frequently/ ...

    } else if (action != null && action.equals(AppWidgetManager.ACTION_APPWIDGET_UPDATE)) {
        Log.d(TAG, "onReceive: ACTION_APPWIDGET_UPDATE :: " + getClass());
        if (extras != null)
        {
            int[] appWidgetIds = extras.getIntArray(AppWidgetManager.EXTRA_APPWIDGET_IDS);
            if (appWidgetIds != null)
            {
                for (int appWidgetId : appWidgetIds) {
                    setUpdateAlarm(context, appWidgetId);
                }
            }
        }

    } else {
        Log.d(TAG, "onReceive: unhandled :: " + action + " :: " + getClass());
    }
}
 
Example 20
Source Project: Spyglass   File: MentionsEditText.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Paste clipboard content between min and max positions.
 * If clipboard content contain the MentionSpan, set the span in copied text.
 */
private void paste(@IntRange(from = 0) int min, @IntRange(from = 0) int max) {
    ClipboardManager clipboard = (ClipboardManager) getContext().getSystemService(Context.CLIPBOARD_SERVICE);
    ClipData clip = clipboard.getPrimaryClip();
    if (clip != null) {
        for (int i = 0; i < clip.getItemCount(); i++) {
            ClipData.Item item = clip.getItemAt(i);
            String selectedText = item.coerceToText(getContext()).toString();
            MentionsEditable text = getMentionsText();
            MentionSpan[] spans = text.getSpans(min, max, MentionSpan.class);
            /*
             * We need to remove the span between min and max. This is required because in
             * {@link SpannableStringBuilder#replace(int, int, CharSequence)} existing spans within
             * the Editable that entirely cover the replaced range are retained, but any that
             * were strictly within the range that was replaced are removed. In our case the existing
             * spans are retained if the selection entirely covers the span. So, we just remove
             * the existing span and replace the new text with that span.
             */
            for (MentionSpan span : spans) {
                if (text.getSpanEnd(span) == min) {
                    // We do not want to remove the span, when we want to paste anything just next
                    // to the existing span. In this case "text.getSpanEnd(span)" will be equal
                    // to min.
                    continue;
                }
                text.removeSpan(span);
            }

            Intent intent = item.getIntent();
            // Just set the plain text if we do not have mentions data in the intent/bundle
            if (intent == null) {
                text.replace(min, max, selectedText);
                continue;
            }
            Bundle bundle = intent.getExtras();
            if (bundle == null) {
                text.replace(min, max, selectedText);
                continue;
            }
            bundle.setClassLoader(getContext().getClassLoader());
            int[] spanStart = bundle.getIntArray(KEY_MENTION_SPAN_STARTS);
            Parcelable[] parcelables = bundle.getParcelableArray(KEY_MENTION_SPANS);
            if (parcelables == null || parcelables.length <= 0 || spanStart == null || spanStart.length <= 0) {
                text.replace(min, max, selectedText);
                continue;
            }

            // Set the MentionSpan in text.
            SpannableStringBuilder s = new SpannableStringBuilder(selectedText);
            for (int j = 0; j < parcelables.length; j++) {
                MentionSpan mentionSpan = (MentionSpan) parcelables[j];
                s.setSpan(mentionSpan, spanStart[j], spanStart[j] + mentionSpan.getDisplayString().length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
            }
            text.replace(min, max, s);
        }
    }
}