List of usage examples for android.os Bundle getSerializable
@Override
@Nullable
public Serializable getSerializable(@Nullable String key)
From source file:com.customdatepicker.time.TimePickerDialog.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (savedInstanceState != null && savedInstanceState.containsKey(KEY_INITIAL_TIME) && savedInstanceState.containsKey(KEY_IS_24_HOUR_VIEW)) { mInitialTime = savedInstanceState.getParcelable(KEY_INITIAL_TIME); mIs24HourMode = savedInstanceState.getBoolean(KEY_IS_24_HOUR_VIEW); mInKbMode = savedInstanceState.getBoolean(KEY_IN_KB_MODE); mTitle = savedInstanceState.getString(KEY_TITLE); mThemeDark = savedInstanceState.getBoolean(KEY_THEME_DARK); mThemeDarkChanged = savedInstanceState.getBoolean(KEY_THEME_DARK_CHANGED); mAccentColor = savedInstanceState.getInt(KEY_ACCENT); mVibrate = savedInstanceState.getBoolean(KEY_VIBRATE); mDismissOnPause = savedInstanceState.getBoolean(KEY_DISMISS); mSelectableTimes = (Timepoint[]) savedInstanceState.getParcelableArray(KEY_SELECTABLE_TIMES); mMinTime = savedInstanceState.getParcelable(KEY_MIN_TIME); mMaxTime = savedInstanceState.getParcelable(KEY_MAX_TIME); mEnableSeconds = savedInstanceState.getBoolean(KEY_ENABLE_SECONDS); mEnableMinutes = savedInstanceState.getBoolean(KEY_ENABLE_MINUTES); mOkResid = savedInstanceState.getInt(KEY_OK_RESID); mOkString = savedInstanceState.getString(KEY_OK_STRING); mOkColor = savedInstanceState.getInt(KEY_OK_COLOR); mCancelResid = savedInstanceState.getInt(KEY_CANCEL_RESID); mCancelString = savedInstanceState.getString(KEY_CANCEL_STRING); mCancelColor = savedInstanceState.getInt(KEY_CANCEL_COLOR); mVersion = (Version) savedInstanceState.getSerializable(KEY_VERSION); }/* ww w .j a v a 2s . c o m*/ }
From source file:com.zzisoo.toylibrary.fragment.ToyListViewFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.toy_list_view_frag, container, false); mToyListView = (ObservableRecyclerView) rootView.findViewById(R.id.toyListRecyclerView); ((BaseActivity) mContext).mScrollableChildView = mToyListView; mToyListView.setOnScrollListener(new RecyclerView.OnScrollListener() { @Override//from ww w . j av a 2 s . c om public void onScrollStateChanged(RecyclerView recyclerView, int newState) { super.onScrollStateChanged(recyclerView, newState); int visibleItemCount = recyclerView.getChildCount(); int totalItemCount = recyclerView.getLayoutManager().getItemCount(); lastScrollPosition = ((LinearLayoutManager) recyclerView.getLayoutManager()) .findFirstVisibleItemPosition(); Log.e(TAG, visibleItemCount + "/" + totalItemCount + "/" + lastScrollPosition); } @Override public void onScrolled(RecyclerView recyclerView, int dx, int dy) { super.onScrolled(recyclerView, dx, dy); } }); if (Config.IS_HIDDENABLE_TOOLBAR) { mToyListView.setScrollViewCallbacks(new ObservableScrollViewCallbacks() { @Override public void onScrollChanged(int i, boolean b, boolean b1) { } @Override public void onDownMotionEvent() { } @Override public void onUpOrCancelMotionEvent(ScrollState scrollState) { BaseActivity act = (BaseActivity) mContext; Log.e("DEBUG", "onUpOrCancelMotionEvent: " + scrollState); if (scrollState == ScrollState.UP) { if (act.toolbarIsShown()) { act.hideToolbar(); } } else if (scrollState == ScrollState.DOWN) { if (act.toolbarIsHidden()) { act.showToolbar(); } } } }); } rootView.setTag(TAG); mLayoutManager = new LinearLayoutManager(getActivity()); mActivityHandler = new Handler() { @Override public void handleMessage(Message msg) { super.handleMessage(msg); if (msg.arg1 == MSG_FINISH) { getActivity().finish(); } else { Toy[] list = (Toy[]) msg.obj; Gson gson = new Gson(); String strList = gson.toJson(list); mAdapter = new ToyListAdapter(list); mToyListView.setAdapter(mAdapter); } } }; String oldData = mPref.getStringPref(SharedPref.PREF_TOYS_LIST); if (oldData.equals(SharedPref.NODATA_STRING)) { getData(); } else { dataLoad(oldData); } if (savedInstanceState != null) { // Restore saved layout manager type. mLayoutType = (LayoutManagerType) savedInstanceState.getSerializable(KEY_LAYOUT_MANAGER); } else { mLayoutType = LayoutManagerType.GRID_LAYOUT_MANAGER; } setRecyclerViewLayoutManager(LayoutManagerType.GRID_LAYOUT_MANAGER); return rootView; }
From source file:com.nbplus.iotlib.IoTInterface.java
private void handleResponse(Bundle b) { int cmd = b.getInt(IoTServiceCommand.KEY_CMD, -1); switch (cmd) { case IoTServiceCommand.DEVICE_DISCONNECT_ALL: { Log.d(TAG, "DEVICE_DISCONNECT_ALL received.. Start retrieve... "); if (mIsEmergencyDataCollecting) { sendConnectToEmergencyDevice(); } else {/* ww w. j a v a 2 s . co m*/ mCurrentRetrieveIndex = 0; if (mServiceStatus == IoTServiceStatus.RUNNING) { sendConnectToDeviceMessage(mCurrentRetrieveIndex); } else { Intent intent = new Intent(IoTConstants.ACTION_IOT_DATA_SYNC_COMPLETED); LocalBroadcastManager.getInstance(mCtx).sendBroadcast(intent); } } break; } case IoTServiceCommand.REGISTER_SERVICE: { b.setClassLoader(IoTResultCodes.class.getClassLoader()); IoTResultCodes resultCode = (IoTResultCodes) b.getSerializable(IoTServiceCommand.KEY_RESULT); if (resultCode != null && resultCode.equals(IoTResultCodes.SUCCESS)) { // success Log.d(TAG, ">> IoT Register service success..."); if (mBondedWithServerList.size() > 0 && (mBondedEmergencyDeviceNumbers > 0 || mBondedKeepaliveDeviceNumbers > 0)) { Bundle extras = new Bundle(); extras.putBoolean(IoTServiceCommand.KEY_DATA, true); sendMessageToService(IoTServiceCommand.SCANNING_START, extras); } else { Bundle extras = new Bundle(); extras.putBoolean(IoTServiceCommand.KEY_DATA, false); sendMessageToService(IoTServiceCommand.SCANNING_STOP, extras); } } else { Log.w(TAG, ">> IoT Register service failed code = " + resultCode); mErrorCodes = resultCode; } break; } case IoTServiceCommand.UNREGISTER_SERVICE: { b.setClassLoader(IoTResultCodes.class.getClassLoader()); IoTResultCodes resultCode = (IoTResultCodes) b.getSerializable(IoTServiceCommand.KEY_RESULT); if (resultCode != null && resultCode.equals(IoTResultCodes.SUCCESS)) { // success Log.d(TAG, ">> IoT Register service success..."); } else { Log.w(TAG, ">> IoT Register service failed code = " + resultCode); } break; } case IoTServiceCommand.DEVICE_CONNECT: { b.setClassLoader(IoTResultCodes.class.getClassLoader()); IoTResultCodes resultCode = (IoTResultCodes) b.getSerializable(IoTServiceCommand.KEY_RESULT); if (resultCode != null && resultCode.equals(IoTResultCodes.SUCCESS)) { // success Log.d(TAG, ">> IoT DEVICE_CONNECT success..."); } else { Log.w(TAG, ">> IoT DEVICE_CONNECT failed code = " + resultCode); String deviceId = b.getString(IoTServiceCommand.KEY_DEVICE_UUID); if (deviceId != null && mKeepAliveDeviceList.containsKey(deviceId)) { Log.d(TAG, "Keep alive device connection failed."); mKeepAliveDeviceList.remove(deviceId); return; } if (IoTResultCodes.DEVICE_CONNECTION_NOT_RESPOND.equals(resultCode) && mConnectionRetryCount < MAX_CONNECTION_RETRY) { if (mServiceStatus != IoTServiceStatus.RUNNING) { mCurrentRetrieveIndex = -1; mCurrentRetrieveDevice = null; if (mIsEmergencyDataCollecting) { mEmergencyDeviceList.clear(); mIsEmergencyDataCollecting = false; if (mIsWaitingForceDataSync) { mIsWaitingForceDataSync = false; Intent intent = new Intent(IoTConstants.ACTION_IOT_DATA_SYNC_COMPLETED); LocalBroadcastManager.getInstance(mCtx).sendBroadcast(intent); } } else { Intent intent = new Intent(IoTConstants.ACTION_IOT_DATA_SYNC_COMPLETED); LocalBroadcastManager.getInstance(mCtx).sendBroadcast(intent); } break; } Log.d(TAG, "mConnectionRetryCount = " + mConnectionRetryCount); mConnectionRetryCount++; Bundle extras = new Bundle(); IoTHandleData data = new IoTHandleData(); data.setDeviceId(mCurrentRetrieveDevice.getDeviceId()); data.setDeviceTypeId(mCurrentRetrieveDevice.getDeviceTypeId()); extras.putParcelable(IoTServiceCommand.KEY_DATA, data); sendMessageToService(IoTServiceCommand.DEVICE_CONNECT, extras); break; } if (mIsEmergencyDataCollecting) { sendConnectToEmergencyDevice(); } else { if (mCurrentRetrieveIndex + 1 < mBondedWithServerList.size()) { mCurrentRetrieveIndex++; sendConnectToDeviceMessage(mCurrentRetrieveIndex); } else { Log.d(TAG, "Retrieving all devices.. completed"); mCurrentRetrieveIndex = -1; mCurrentRetrieveDevice = null; mHandler.removeMessages(HANDLER_RETRIEVE_IOT_DEVICES); mHandler.sendEmptyMessageDelayed(HANDLER_RETRIEVE_IOT_DEVICES, RETRIEVE_IOT_DEVICE_DATA_PERIOD); sendCollectedDataToServer(); } } } break; } case IoTServiceCommand.DEVICE_DISCONNECT: { b.setClassLoader(IoTResultCodes.class.getClassLoader()); IoTResultCodes resultCode = (IoTResultCodes) b.getSerializable(IoTServiceCommand.KEY_RESULT); if (resultCode != null && resultCode.equals(IoTResultCodes.SUCCESS)) { // success Log.d(TAG, ">> IoT DEVICE_DISCONNECT success..."); } else { Log.w(TAG, ">> IoT DEVICE_DISCONNECT failed code = " + resultCode); if (mIsEmergencyDataCollecting) { sendConnectToEmergencyDevice(); } else { if (mCurrentRetrieveIndex + 1 < mBondedWithServerList.size()) { mCurrentRetrieveIndex++; sendConnectToDeviceMessage(mCurrentRetrieveIndex); } else { mCurrentRetrieveIndex = -1; mCurrentRetrieveDevice = null; mHandler.removeMessages(HANDLER_RETRIEVE_IOT_DEVICES); mHandler.sendEmptyMessageDelayed(HANDLER_RETRIEVE_IOT_DEVICES, RETRIEVE_IOT_DEVICE_DATA_PERIOD); sendCollectedDataToServer(); } } } break; } case IoTServiceCommand.DEVICE_READ_DATA: case IoTServiceCommand.DEVICE_WRITE_DATA: case IoTServiceCommand.DEVICE_SET_NOTIFICATION: { b.setClassLoader(IoTResultCodes.class.getClassLoader()); IoTResultCodes resultCode = (IoTResultCodes) b.getSerializable(IoTServiceCommand.KEY_RESULT); if (resultCode != null && resultCode.equals(IoTResultCodes.SUCCESS)) { // success Log.d(TAG, ">> IoT READ_WRITE_SET_NOTIFICATION success..."); } else { Log.e(TAG, ">> IoT READ_WRITE_SET_NOTIFICATION failed code = " + resultCode); mHandler.removeMessages(HANDLER_WAIT_FOR_NOTIFY_DATA); Message disconnMsg = new Message(); disconnMsg.what = HANDLER_WAIT_FOR_NOTIFY_DATA; disconnMsg.arg1 = 1; mHandler.sendMessage(disconnMsg); } break; } default: Log.d(TAG, "unknown command.."); break; } }
From source file:com.facebook.LegacyTokenCacheTest.java
@Test public void testAllTypes() { Bundle originalBundle = new Bundle(); putBoolean(BOOLEAN_KEY, originalBundle); putBooleanArray(BOOLEAN_ARRAY_KEY, originalBundle); putByte(BYTE_KEY, originalBundle);/*from www . jav a 2s.co m*/ putByteArray(BYTE_ARRAY_KEY, originalBundle); putShort(SHORT_KEY, originalBundle); putShortArray(SHORT_ARRAY_KEY, originalBundle); putInt(INT_KEY, originalBundle); putIntArray(INT_ARRAY_KEY, originalBundle); putLong(LONG_KEY, originalBundle); putLongArray(LONG_ARRAY_KEY, originalBundle); putFloat(FLOAT_KEY, originalBundle); putFloatArray(FLOAT_ARRAY_KEY, originalBundle); putDouble(DOUBLE_KEY, originalBundle); putDoubleArray(DOUBLE_ARRAY_KEY, originalBundle); putChar(CHAR_KEY, originalBundle); putCharArray(CHAR_ARRAY_KEY, originalBundle); putString(STRING_KEY, originalBundle); putStringList(STRING_LIST_KEY, originalBundle); originalBundle.putSerializable(SERIALIZABLE_KEY, AccessTokenSource.FACEBOOK_APPLICATION_WEB); ensureApplicationContext(); LegacyTokenHelper cache = new LegacyTokenHelper(RuntimeEnvironment.application); cache.save(originalBundle); LegacyTokenHelper cache2 = new LegacyTokenHelper(RuntimeEnvironment.application); Bundle cachedBundle = cache2.load(); assertEquals(originalBundle.getBoolean(BOOLEAN_KEY), cachedBundle.getBoolean(BOOLEAN_KEY)); assertArrayEquals(originalBundle.getBooleanArray(BOOLEAN_ARRAY_KEY), cachedBundle.getBooleanArray(BOOLEAN_ARRAY_KEY)); assertEquals(originalBundle.getByte(BYTE_KEY), cachedBundle.getByte(BYTE_KEY)); assertArrayEquals(originalBundle.getByteArray(BYTE_ARRAY_KEY), cachedBundle.getByteArray(BYTE_ARRAY_KEY)); assertEquals(originalBundle.getShort(SHORT_KEY), cachedBundle.getShort(SHORT_KEY)); assertArrayEquals(originalBundle.getShortArray(SHORT_ARRAY_KEY), cachedBundle.getShortArray(SHORT_ARRAY_KEY)); assertEquals(originalBundle.getInt(INT_KEY), cachedBundle.getInt(INT_KEY)); assertArrayEquals(originalBundle.getIntArray(INT_ARRAY_KEY), cachedBundle.getIntArray(INT_ARRAY_KEY)); assertEquals(originalBundle.getLong(LONG_KEY), cachedBundle.getLong(LONG_KEY)); assertArrayEquals(originalBundle.getLongArray(LONG_ARRAY_KEY), cachedBundle.getLongArray(LONG_ARRAY_KEY)); assertEquals(originalBundle.getFloat(FLOAT_KEY), cachedBundle.getFloat(FLOAT_KEY), TestUtils.DOUBLE_EQUALS_DELTA); assertArrayEquals(originalBundle.getFloatArray(FLOAT_ARRAY_KEY), cachedBundle.getFloatArray(FLOAT_ARRAY_KEY)); assertEquals(originalBundle.getDouble(DOUBLE_KEY), cachedBundle.getDouble(DOUBLE_KEY), TestUtils.DOUBLE_EQUALS_DELTA); assertArrayEquals(originalBundle.getDoubleArray(DOUBLE_ARRAY_KEY), cachedBundle.getDoubleArray(DOUBLE_ARRAY_KEY)); assertEquals(originalBundle.getChar(CHAR_KEY), cachedBundle.getChar(CHAR_KEY)); assertArrayEquals(originalBundle.getCharArray(CHAR_ARRAY_KEY), cachedBundle.getCharArray(CHAR_ARRAY_KEY)); assertEquals(originalBundle.getString(STRING_KEY), cachedBundle.getString(STRING_KEY)); assertListEquals(originalBundle.getStringArrayList(STRING_LIST_KEY), cachedBundle.getStringArrayList(STRING_LIST_KEY)); assertEquals(originalBundle.getSerializable(SERIALIZABLE_KEY), cachedBundle.getSerializable(SERIALIZABLE_KEY)); }
From source file:com.onegravity.contactpicker.core.ContactPickerActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // check if all custom attributes are defined if (!checkTheming()) { finish();/*from ww w. j av a 2 s . c om*/ return; } /* * Check if we have the READ_CONTACTS permission, if not --> terminate. */ try { int pid = android.os.Process.myPid(); PackageManager pckMgr = getPackageManager(); int uid = pckMgr.getApplicationInfo(getComponentName().getPackageName(), PackageManager.GET_META_DATA).uid; enforcePermission(Manifest.permission.READ_CONTACTS, pid, uid, "Contact permission hasn't been granted to this app, terminating."); } catch (PackageManager.NameNotFoundException | SecurityException e) { Log.e(getClass().getSimpleName(), e.getMessage()); finish(); return; } mDefaultTitle = "Select Contacts"; mThemeResId = R.style.Theme_Light; Intent intent = getIntent(); if (savedInstanceState == null) { // /* // * Retrieve default title used if no contacts are selected. // */ // try { // PackageManager pkMgr = getPackageManager(); // ActivityInfo activityInfo = pkMgr.getActivityInfo(getComponentName(), PackageManager.GET_META_DATA); // mDefaultTitle = activityInfo.loadLabel(pkMgr).toString(); // } // catch (PackageManager.NameNotFoundException ignore) { // mDefaultTitle = getTitle().toString(); // } if (intent.hasExtra(EXTRA_PRESELECTED_CONTACTS)) { Collection<Long> preselectedContacts = (Collection<Long>) intent .getSerializableExtra(EXTRA_PRESELECTED_CONTACTS); mSelectedContactIds.addAll(preselectedContacts); } if (intent.hasExtra(EXTRA_PRESELECTED_GROUPS)) { Collection<Long> preselectedGroups = (Collection<Long>) intent .getSerializableExtra(EXTRA_PRESELECTED_GROUPS); mSelectedGroupIds.addAll(preselectedGroups); } // mThemeResId = intent.getIntExtra(EXTRA_THEME, R.style.ContactPicker_Theme_Light); } else { // mDefaultTitle = savedInstanceState.getString("mDefaultTitle"); // // mThemeResId = savedInstanceState.getInt("mThemeResId"); // Retrieve selected contact and group ids. try { mSelectedContactIds = (HashSet<Long>) savedInstanceState.getSerializable(CONTACT_IDS); mSelectedGroupIds = (HashSet<Long>) savedInstanceState.getSerializable(GROUP_IDS); } catch (ClassCastException ignore) { } } /* * Retrieve ContactPictureType. */ String enumName = intent.getStringExtra(EXTRA_CONTACT_BADGE_TYPE); mBadgeType = ContactPictureType.lookup(enumName); /* * Retrieve SelectContactsLimit. */ mSelectContactsLimit = intent.getIntExtra(EXTRA_SELECT_CONTACTS_LIMIT, 0); /* * Retrieve ShowCheckAll. */ mShowCheckAll = mSelectContactsLimit > 0 ? false : intent.getBooleanExtra(EXTRA_SHOW_CHECK_ALL, true); /* * Retrieve OnlyWithPhoneNumbers. */ mOnlyWithPhoneNumbers = intent.getBooleanExtra(EXTRA_ONLY_CONTACTS_WITH_PHONE, false); /* * Retrieve LimitReachedMessage. */ String limitMsg = intent.getStringExtra(EXTRA_LIMIT_REACHED_MESSAGE); if (limitMsg != null) { mLimitReachedMessage = limitMsg; } else { mLimitReachedMessage = getString(R.string.cp_limit_reached, mSelectContactsLimit); } /* * Retrieve ContactDescription. */ enumName = intent.getStringExtra(EXTRA_CONTACT_DESCRIPTION); mDescription = ContactDescription.lookup(enumName); mDescriptionType = intent.getIntExtra(EXTRA_CONTACT_DESCRIPTION_TYPE, ContactsContract.CommonDataKinds.StructuredPostal.TYPE_HOME); /* * Retrieve ContactSortOrder. */ enumName = intent.getStringExtra(EXTRA_CONTACT_SORT_ORDER); mSortOrder = ContactSortOrder.lookup(enumName); setTheme(mThemeResId); setContentView(R.layout.cp_contact_tab_layout); // initialize TabLayout TabLayout tabLayout = (TabLayout) findViewById(R.id.tabContent); tabLayout.setTabMode(TabLayout.MODE_FIXED); tabLayout.setTabGravity(TabLayout.GRAVITY_FILL); TabLayout.Tab tabContacts = tabLayout.newTab(); tabContacts.setText(R.string.cp_contact_tab_title); tabLayout.addTab(tabContacts); TabLayout.Tab tabGroups = tabLayout.newTab(); tabGroups.setText(R.string.cp_group_tab_title); tabLayout.addTab(tabGroups); // initialize ViewPager final ViewPager viewPager = (ViewPager) findViewById(R.id.tabPager); mAdapter = new PagerAdapter(getSupportFragmentManager(), tabLayout.getTabCount(), mSortOrder, mBadgeType, mDescription, mDescriptionType); viewPager.setAdapter(mAdapter); viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout)); tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() { @Override public void onTabSelected(TabLayout.Tab tab) { viewPager.setCurrentItem(tab.getPosition()); } @Override public void onTabUnselected(TabLayout.Tab tab) { } @Override public void onTabReselected(TabLayout.Tab tab) { } }); getSupportActionBar().setDisplayHomeAsUpEnabled(true); }
From source file:com.nbplus.iotlib.IoTInterface.java
private void handleServiceMessage(Message msg) { switch (msg.what) { case IoTServiceCommand.COMMAND_RESPONSE: { Bundle b = msg.getData(); if (b == null) { Log.w(TAG, "bundle data is null"); return; }//from w w w . j a v a 2s .c o m handleResponse(b); break; } // bt command ?? ?. // 3 ? ? ... case HANDLER_COMMAND_NOT_RESPOND: { Log.d(TAG, "HANDLER_COMMAND_NOT_RESPOND retry or next device.."); if (mCommandRetryCount < MAX_CONNECTION_RETRY) { retryDeviceCommand(); } else { mCurrentRetrieveIndex++; sendConnectToDeviceMessage(mCurrentRetrieveIndex); } break; } case IoTServiceCommand.SERVICE_STATUS_NOTIFICATION: { Log.d(TAG, "IoTServiceCommand.SERVICE_STATUS_NOTIFICATION"); Bundle b = msg.getData(); if (b == null) { Log.w(TAG, "bundle data is null"); return; } b.setClassLoader(IoTServiceStatus.class.getClassLoader()); IoTServiceStatus serviceStatus = (IoTServiceStatus) b .getSerializable(IoTServiceCommand.KEY_SERVICE_STATUS); if (mServiceStatus.equals(serviceStatus)) { Log.w(TAG, "same service status received."); return; } mServiceStatus = serviceStatus; Intent intent = new Intent(IoTConstants.ACTION_IOT_SERVICE_STATUS_CHANGED); intent.putExtra(IoTConstants.EXTRA_SERVICE_STATUS, (mServiceStatus == IoTServiceStatus.RUNNING)); LocalBroadcastManager.getInstance(mCtx).sendBroadcast(intent); b.setClassLoader(IoTResultCodes.class.getClassLoader()); mErrorCodes = (IoTResultCodes) b.getSerializable(IoTServiceCommand.KEY_SERVICE_STATUS_CODE); Log.d(TAG, "IoTServiceCommand.SERVICE_STATUS_NOTIFICATION : status = " + mServiceStatus + ", errCode = " + mErrorCodes); if (mServiceStatus == IoTServiceStatus.STOPPED) { Log.d(TAG, "initializeVariablesWhenStop() called"); initializeVariablesWhenStop(); } else if (mServiceStatus == IoTServiceStatus.RUNNING) { Log.d(TAG, "restart device scanning and retrives device data"); if (mBondedWithServerList.size() > 0 && (mBondedEmergencyDeviceNumbers > 0 || mBondedKeepaliveDeviceNumbers > 0)) { Bundle extras = new Bundle(); extras.putBoolean(IoTServiceCommand.KEY_DATA, true); sendMessageToService(IoTServiceCommand.SCANNING_START, extras); } else { Bundle extras = new Bundle(); extras.putBoolean(IoTServiceCommand.KEY_DATA, false); sendMessageToService(IoTServiceCommand.SCANNING_STOP, extras); } // IoT ? ? . mHandler.removeMessages(HANDLER_RETRIEVE_IOT_DEVICES); mHandler.sendEmptyMessageDelayed(HANDLER_RETRIEVE_IOT_DEVICES, 10 * 1000); } break; } case IoTServiceCommand.DEVICE_LIST_NOTIFICATION: { Bundle b = msg.getData(); handleDeviceListNotification(b); break; } case IoTServiceCommand.DEVICE_CONNECTED: { Bundle b = msg.getData(); handleDeviceConnectedNotification(b); break; } case IoTServiceCommand.DEVICE_DISCONNECTED: { mHandler.removeMessages(HANDLER_WAIT_FOR_NOTIFY_DATA); Bundle b = msg.getData(); handleDeviceDisconnectedNotification(b); break; } case IoTServiceCommand.DEVICE_WRITE_DATA_RESULT: case IoTServiceCommand.DEVICE_SET_NOTIFICATION_RESULT: { Log.d(TAG, "IoTServiceCommand.DEVICE_SET_NOTIFICATION_RESULT received"); Bundle b = msg.getData(); b.setClassLoader(IoTResultCodes.class.getClassLoader()); IoTResultCodes resultCode = (IoTResultCodes) b.getSerializable(IoTServiceCommand.KEY_RESULT); if (IoTResultCodes.SUCCESS.equals(resultCode)) { // success set notifications. Log.d(TAG, "success set notification.. proceed next command"); b.setClassLoader(IoTHandleData.class.getClassLoader()); IoTHandleData resultData = b.getParcelable(IoTServiceCommand.KEY_DATA); if (resultData != null) { // xiaomi if (resultData.getCharacteristicUuid().equals(GattAttributes.MISCALE_CHARACTERISTIC_2A2F)) { handleXiaomiScale(msg.what, resultData); } else if (resultData.getCharacteristicUuid().equals(GattAttributes.SMART_SENSOR)) { handleSmartSensor(msg.what, resultData); } else if (resultData.getServiceUuid().equals(GattAttributes.GLUCOSE_SERVICE_UUID)) { handleGlucoseMeasurement(msg.what, resultData); } else if (resultData.getServiceUuid().equals(GattAttributes.SMART_BAND_SERVICE_UUID)) { handleSmartBand(msg.what, resultData); } else { proceedDeviceCommand(); } } } else { // fail set notifications. Log.d(TAG, "fail set notification.. disconnect device"); mHandler.removeMessages(HANDLER_WAIT_FOR_NOTIFY_DATA); Message disconnMsg = new Message(); disconnMsg.what = HANDLER_WAIT_FOR_NOTIFY_DATA; disconnMsg.arg1 = 1; mHandler.sendMessage(disconnMsg); } break; } case IoTServiceCommand.DEVICE_READ_DATA_RESULT: case IoTServiceCommand.DEVICE_NOTIFICATION_DATA: { // read ? notification ? . //Log.d(TAG, "IoTServiceCommand.DEVICE_NOTIFICATION_DATA received"); try { Bundle b = msg.getData(); b.setClassLoader(IoTHandleData.class.getClassLoader()); IoTHandleData resultData = b.getParcelable(IoTServiceCommand.KEY_DATA); if (resultData != null) { // xiaomi if (resultData.getCharacteristicUuid().equals(GattAttributes.MISCALE_CHARACTERISTIC_2A2F)) { handleXiaomiScale(msg.what, resultData); } else if (resultData.getCharacteristicUuid().equals(GattAttributes.SMART_SENSOR)) { handleSmartSensor(msg.what, resultData); } else if (resultData.getServiceUuid().equals(GattAttributes.GLUCOSE_SERVICE_UUID)) { handleGlucoseMeasurement(msg.what, resultData); } else { if (mIsEmergencyDataCollecting) { handleSmartBand(msg.what, resultData); } else { // TODO : what??? proceedDeviceCommand(); } } } } catch (Exception e) { } break; } case HANDLER_RETRIEVE_IOT_DEVICES: { Log.d(TAG, "HANDLER_RETRIEVE_IOT_DEVICES received.. Clear all previous connection first.."); if (mServiceStatus != IoTServiceStatus.RUNNING) { Intent intent = new Intent(IoTConstants.ACTION_IOT_DATA_SYNC_COMPLETED); LocalBroadcastManager.getInstance(mCtx).sendBroadcast(intent); } else { // ? ?? ? . Bundle extras = new Bundle(); extras.putBoolean(IoTServiceCommand.KEY_DATA, false); sendMessageToService(IoTServiceCommand.SCANNING_STOP, extras); mHandler.removeMessages(HANDLER_RETRIEVE_IOT_DEVICES); sendMessageToService(IoTServiceCommand.DEVICE_DISCONNECT_ALL, null); } break; } case HANDLER_WAIT_FOR_NOTIFY_DATA: { mHandler.removeMessages(HANDLER_WAIT_FOR_NOTIFY_DATA); if (mCurrentRetrieveDevice == null || msg.arg1 == 0) { // ? ?? ?? ... ? // ? . return; } Log.w(TAG, "I have no more scenario for this device = " + mCurrentRetrieveDevice.getDeviceName()); Bundle extras = new Bundle(); IoTHandleData data = new IoTHandleData(); data.setDeviceId(mCurrentRetrieveDevice.getDeviceId()); data.setDeviceTypeId(mCurrentRetrieveDevice.getDeviceTypeId()); extras.putParcelable(IoTServiceCommand.KEY_DATA, data); sendMessageToService(IoTServiceCommand.DEVICE_DISCONNECT, extras); break; } case HANDLER_SEND_IOT_DEVICE_DATA_TASK_COMPLETED: { Log.d(TAG, "HANDLER_SEND_IOT_DEVICE_DATA_TASK_COMPLETED received... "); Intent intent = new Intent(IoTConstants.ACTION_IOT_DATA_SYNC_COMPLETED); LocalBroadcastManager.getInstance(mCtx).sendBroadcast(intent); BaseApiResult result = (BaseApiResult) msg.obj; if (BaseApiResult.RESULT_SUCCESS.equals(result.getResultCode())) { Log.d(TAG, "Send collected data to server success.."); } else { Log.w(TAG, "Send collected data to server failed.. set unsent data"); Bundle extras = msg.getData(); if (extras != null) { IoTCollectedData data = extras.getParcelable("data"); if (data == null) { break; } mCollectedData.addAllIoTData(data.getIoTData()); IoTServicePreference.setUnSentCollectedData(mCtx, mGson.toJson(mCollectedData)); } } break; } default: break; } }
From source file:com.borax12.materialdaterangepicker.date.DatePickerDialog.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); View view = inflater.inflate(R.layout.range_date_picker_dialog, container, false); tabHost = (TabHost) view.findViewById(R.id.tabHost); tabHost.findViewById(R.id.tabHost);/*w w w.jav a2 s . c om*/ tabHost.setup(); final Activity activity = getActivity(); TabHost.TabSpec startDatePage = tabHost.newTabSpec("start"); startDatePage.setContent(R.id.start_date_group); startDatePage.setIndicator((startTitle != null && !startTitle.isEmpty()) ? startTitle : activity.getResources().getString(R.string.mdtrp_from)); TabHost.TabSpec endDatePage = tabHost.newTabSpec("end"); endDatePage.setContent(R.id.end_date_group); endDatePage.setIndicator((endTitle != null && !endTitle.isEmpty()) ? endTitle : activity.getResources().getString(R.string.mdtrp_to)); tabHost.addTab(startDatePage); tabHost.addTab(endDatePage); mDayOfWeekView = (TextView) view.findViewById(R.id.date_picker_header); mMonthAndDayView = (LinearLayout) view.findViewById(R.id.date_picker_month_and_day); mMonthAndDayViewEnd = (LinearLayout) view.findViewById(R.id.date_picker_month_and_day_end); mMonthAndDayView.setOnClickListener(this); mMonthAndDayViewEnd.setOnClickListener(this); mSelectedMonthTextView = (TextView) view.findViewById(R.id.date_picker_month); mSelectedMonthTextViewEnd = (TextView) view.findViewById(R.id.date_picker_month_end); mSelectedDayTextView = (TextView) view.findViewById(R.id.date_picker_day); mSelectedDayTextViewEnd = (TextView) view.findViewById(R.id.date_picker_day_end); mYearView = (TextView) view.findViewById(R.id.date_picker_year); mYearViewEnd = (TextView) view.findViewById(R.id.date_picker_year_end); mYearView.setOnClickListener(this); mYearViewEnd.setOnClickListener(this); int listPosition = -1; int listPositionOffset = 0; int listPositionEnd = -1; int listPositionOffsetEnd = 0; int currentView = MONTH_AND_DAY_VIEW; int currentViewEnd = MONTH_AND_DAY_VIEW; if (savedInstanceState != null) { mWeekStart = savedInstanceState.getInt(KEY_WEEK_START); mWeekStartEnd = savedInstanceState.getInt(KEY_WEEK_START_END); mMinYear = savedInstanceState.getInt(KEY_YEAR_START); mMaxYear = savedInstanceState.getInt(KEY_MAX_YEAR); currentView = savedInstanceState.getInt(KEY_CURRENT_VIEW); currentViewEnd = savedInstanceState.getInt(KEY_CURRENT_VIEW_END); listPosition = savedInstanceState.getInt(KEY_LIST_POSITION); listPositionOffset = savedInstanceState.getInt(KEY_LIST_POSITION_OFFSET); listPositionEnd = savedInstanceState.getInt(KEY_LIST_POSITION_END); listPositionOffsetEnd = savedInstanceState.getInt(KEY_LIST_POSITION_OFFSET_END); mMinDate = (Calendar) savedInstanceState.getSerializable(KEY_MIN_DATE); mMaxDate = (Calendar) savedInstanceState.getSerializable(KEY_MAX_DATE); mMinDateEnd = (Calendar) savedInstanceState.getSerializable(KEY_MIN_DATE_END); mMaxDateEnd = (Calendar) savedInstanceState.getSerializable(KEY_MAX_DATE_END); highlightedDays = (Calendar[]) savedInstanceState.getSerializable(KEY_HIGHLIGHTED_DAYS); selectableDays = (Calendar[]) savedInstanceState.getSerializable(KEY_SELECTABLE_DAYS); highlightedDaysEnd = (Calendar[]) savedInstanceState.getSerializable(KEY_HIGHLIGHTED_DAYS_END); selectableDaysEnd = (Calendar[]) savedInstanceState.getSerializable(KEY_SELECTABLE_DAYS_END); mThemeDark = savedInstanceState.getBoolean(KEY_THEME_DARK); mAccentColor = savedInstanceState.getInt(KEY_ACCENT); mVibrate = savedInstanceState.getBoolean(KEY_VIBRATE); mDismissOnPause = savedInstanceState.getBoolean(KEY_DISMISS); } mDayPickerView = new com.borax12.materialdaterangepicker.date.SimpleDayPickerView(activity, this); mYearPickerView = new com.borax12.materialdaterangepicker.date.YearPickerView(activity, this); mDayPickerViewEnd = new com.borax12.materialdaterangepicker.date.SimpleDayPickerView(activity, this); mYearPickerViewEnd = new com.borax12.materialdaterangepicker.date.YearPickerView(activity, this); Resources res = getResources(); mDayPickerDescription = res.getString(R.string.mdtrp_day_picker_description); mSelectDay = res.getString(R.string.mdtrp_select_day); mYearPickerDescription = res.getString(R.string.mdtrp_year_picker_description); mSelectYear = res.getString(R.string.mdtrp_select_year); int bgColorResource = mThemeDark ? R.color.mdtrp_date_picker_view_animator_dark_theme : R.color.mdtrp_date_picker_view_animator; view.setBackgroundColor(ContextCompat.getColor(activity, bgColorResource)); mAnimator = (com.borax12.materialdaterangepicker.date.AccessibleDateAnimator) view .findViewById(R.id.animator); mAnimatorEnd = (com.borax12.materialdaterangepicker.date.AccessibleDateAnimator) view .findViewById(R.id.animator_end); mAnimator.addView(mDayPickerView); mAnimator.addView(mYearPickerView); mAnimator.setDateMillis(mCalendar.getTimeInMillis()); // TODO: Replace with animation decided upon by the design team. Animation animation = new AlphaAnimation(0.0f, 1.0f); animation.setDuration(ANIMATION_DURATION); mAnimator.setInAnimation(animation); // TODO: Replace with animation decided upon by the design team. Animation animation2 = new AlphaAnimation(1.0f, 0.0f); animation2.setDuration(ANIMATION_DURATION); mAnimator.setOutAnimation(animation2); mAnimatorEnd.addView(mDayPickerViewEnd); mAnimatorEnd.addView(mYearPickerViewEnd); mAnimatorEnd.setDateMillis(mCalendarEnd.getTimeInMillis()); // TODO: Replace with animation decided upon by the design team. Animation animationEnd = new AlphaAnimation(0.0f, 1.0f); animationEnd.setDuration(ANIMATION_DURATION); mAnimatorEnd.setInAnimation(animation); // TODO: Replace with animation decided upon by the design team. Animation animation2End = new AlphaAnimation(1.0f, 0.0f); animation2End.setDuration(ANIMATION_DURATION); mAnimatorEnd.setOutAnimation(animation2); Button okButton = (Button) view.findViewById(R.id.ok); okButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tryVibrate(); if (mCallBack != null) { mCallBack.onDateSet(DatePickerDialog.this, mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH), mCalendarEnd.get(Calendar.YEAR), mCalendarEnd.get(Calendar.MONTH), mCalendarEnd.get(Calendar.DAY_OF_MONTH)); } dismiss(); } }); okButton.setTypeface(TypefaceHelper.get(activity, "Roboto-Medium")); Button cancelButton = (Button) view.findViewById(R.id.cancel); cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tryVibrate(); if (getDialog() != null) getDialog().cancel(); } }); cancelButton.setTypeface(TypefaceHelper.get(activity, "Roboto-Medium")); cancelButton.setVisibility(isCancelable() ? View.VISIBLE : View.GONE); //If an accent color has not been set manually, try and get it from the context if (mAccentColor == -1) { int accentColor = Utils.getAccentColorFromThemeIfAvailable(getActivity()); if (accentColor != -1) { mAccentColor = accentColor; } } if (mAccentColor != -1) { if (mDayOfWeekView != null) mDayOfWeekView.setBackgroundColor(Utils.darkenColor(mAccentColor)); view.findViewById(R.id.day_picker_selected_date_layout).setBackgroundColor(mAccentColor); view.findViewById(R.id.day_picker_selected_date_layout_end).setBackgroundColor(mAccentColor); okButton.setTextColor(mAccentColor); cancelButton.setTextColor(mAccentColor); mYearPickerView.setAccentColor(mAccentColor); mDayPickerView.setAccentColor(mAccentColor); mYearPickerViewEnd.setAccentColor(mAccentColor); mDayPickerViewEnd.setAccentColor(mAccentColor); } updateDisplay(false); setCurrentView(currentView); if (listPosition != -1) { if (currentView == MONTH_AND_DAY_VIEW) { mDayPickerView.postSetSelection(listPosition); } else if (currentView == YEAR_VIEW) { mYearPickerView.postSetSelectionFromTop(listPosition, listPositionOffset); } } if (listPositionEnd != -1) { if (currentViewEnd == MONTH_AND_DAY_VIEW) { mDayPickerViewEnd.postSetSelection(listPositionEnd); } else if (currentViewEnd == YEAR_VIEW) { mYearPickerViewEnd.postSetSelectionFromTop(listPositionEnd, listPositionOffsetEnd); } } mHapticFeedbackController = new HapticFeedbackController(activity); tabHost.setOnTabChangedListener(new TabHost.OnTabChangeListener() { @Override public void onTabChanged(String tabId) { com.borax12.materialdaterangepicker.date.MonthAdapter.CalendarDay calendarDay; if (tabId.equals("start")) { calendarDay = new com.borax12.materialdaterangepicker.date.MonthAdapter.CalendarDay( mCalendar.getTimeInMillis()); mDayPickerView.goTo(calendarDay, true, true, false); } else { calendarDay = new com.borax12.materialdaterangepicker.date.MonthAdapter.CalendarDay( mCalendarEnd.getTimeInMillis()); mDayPickerViewEnd.goTo(calendarDay, true, true, false); } } }); return view; }
From source file:com.android.mail.compose.ComposeActivity.java
private void initAttachmentsFromIntent(Intent intent) { Bundle extras = intent.getExtras(); if (extras == null) { extras = Bundle.EMPTY;/* ww w. java 2 s .c o m*/ } final String action = intent.getAction(); if (!mAttachmentsChanged) { long totalSize = 0; if (extras.containsKey(EXTRA_ATTACHMENTS)) { final String[] uris = (String[]) extras.getSerializable(EXTRA_ATTACHMENTS); final ArrayList<Uri> parsedUris = Lists.newArrayListWithCapacity(uris.length); for (String uri : uris) { parsedUris.add(Uri.parse(uri)); } totalSize += handleAttachmentUrisFromIntent(parsedUris); } if (extras.containsKey(Intent.EXTRA_STREAM)) { if (Intent.ACTION_SEND_MULTIPLE.equals(action)) { final ArrayList<Uri> uris = extras.getParcelableArrayList(Intent.EXTRA_STREAM); totalSize += handleAttachmentUrisFromIntent(uris); } else { final Uri uri = extras.getParcelable(Intent.EXTRA_STREAM); final ArrayList<Uri> uris = Lists.newArrayList(uri); totalSize += handleAttachmentUrisFromIntent(uris); } } if (totalSize > 0) { mAttachmentsChanged = true; updateSaveUi(); Analytics.getInstance().sendEvent("send_intent_with_attachments", Integer.toString(getAttachments().size()), null, totalSize); } } }
From source file:co.taqat.call.LinphoneActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { //This must be done before calling super.onCreate(). super.onCreate(savedInstanceState); if (getResources().getBoolean(R.bool.orientation_portrait_only)) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); }// w w w . j ava 2 s. c o m boolean useFirstLoginActivity = getResources().getBoolean(R.bool.display_account_assistant_at_first_start); if (LinphonePreferences.instance().isProvisioningLoginViewEnabled()) { Intent wizard = new Intent(); wizard.setClass(this, RemoteProvisioningLoginActivity.class); wizard.putExtra("Domain", LinphoneManager.getInstance().wizardLoginViewDomain); startActivity(wizard); finish(); return; } else if (savedInstanceState == null && (useFirstLoginActivity && LinphonePreferences.instance().isFirstLaunch())) { if (LinphonePreferences.instance().getAccountCount() > 0) { LinphonePreferences.instance().firstLaunchSuccessful(); } else { startActivity(new Intent().setClass(this, AssistantActivity.class)); finish(); return; } } if (getIntent() != null && getIntent().getExtras() != null) { newProxyConfig = getIntent().getExtras().getBoolean("isNewProxyConfig"); } if (getResources().getBoolean(R.bool.use_linphone_tag)) { if (getPackageManager().checkPermission(Manifest.permission.WRITE_SYNC_SETTINGS, getPackageName()) != PackageManager.PERMISSION_GRANTED) { checkSyncPermission(); } else { ContactsManager.getInstance().initializeSyncAccount(getApplicationContext(), getContentResolver()); } } else { ContactsManager.getInstance().initializeContactManager(getApplicationContext(), getContentResolver()); } setContentView(R.layout.main); instance = this; fragmentsHistory = new ArrayList<FragmentsAvailable>(); pendingFragmentTransaction = FragmentsAvailable.UNKNOW; initButtons(); initSideMenu(); currentFragment = FragmentsAvailable.EMPTY; if (savedInstanceState == null) { changeCurrentFragment(FragmentsAvailable.DIALER, getIntent().getExtras()); } else { currentFragment = (FragmentsAvailable) savedInstanceState.getSerializable("currentFragment"); } mListener = new LinphoneCoreListenerBase() { @Override public void messageReceived(LinphoneCore lc, LinphoneChatRoom cr, LinphoneChatMessage message) { displayMissedChats(getUnreadMessageCount()); } @Override public void registrationState(LinphoneCore lc, LinphoneProxyConfig proxy, LinphoneCore.RegistrationState state, String smessage) { if (state.equals(RegistrationState.RegistrationCleared)) { if (lc != null) { LinphoneAuthInfo authInfo = lc.findAuthInfo(proxy.getIdentity(), proxy.getRealm(), proxy.getDomain()); if (authInfo != null) lc.removeAuthInfo(authInfo); } } refreshAccounts(); if (getResources().getBoolean(R.bool.use_phone_number_validation)) { if (state.equals(RegistrationState.RegistrationOk)) { LinphoneManager.getInstance().isAccountWithAlias(); } } if (state.equals(RegistrationState.RegistrationFailed) && newProxyConfig) { newProxyConfig = false; if (proxy.getError() == Reason.BadCredentials) { //displayCustomToast(getString(R.string.error_bad_credentials), Toast.LENGTH_LONG); } if (proxy.getError() == Reason.Unauthorized) { displayCustomToast(getString(R.string.error_unauthorized), Toast.LENGTH_LONG); } if (proxy.getError() == Reason.IOError) { displayCustomToast(getString(R.string.error_io_error), Toast.LENGTH_LONG); } } } @Override public void callState(LinphoneCore lc, LinphoneCall call, LinphoneCall.State state, String message) { if (state == State.IncomingReceived) { startActivity(new Intent(LinphoneActivity.instance(), CallIncomingActivity.class)); } else if (state == State.OutgoingInit || state == State.OutgoingProgress) { startActivity(new Intent(LinphoneActivity.instance(), CallOutgoingActivity.class)); } else if (state == State.CallEnd || state == State.Error || state == State.CallReleased) { resetClassicMenuLayoutAndGoBackToCallIfStillRunning(); } int missedCalls = LinphoneManager.getLc().getMissedCallsCount(); displayMissedCalls(missedCalls); } }; int missedCalls = LinphoneManager.getLc().getMissedCallsCount(); displayMissedCalls(missedCalls); int rotation = getWindowManager().getDefaultDisplay().getRotation(); switch (rotation) { case Surface.ROTATION_0: rotation = 0; break; case Surface.ROTATION_90: rotation = 90; break; case Surface.ROTATION_180: rotation = 180; break; case Surface.ROTATION_270: rotation = 270; break; } LinphoneManager.getLc().setDeviceRotation(rotation); mAlwaysChangingPhoneAngle = rotation; }
From source file:com.leavjenn.smoothdaterangepicker.date.SmoothDateRangePickerFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Log.d(TAG, "onCreateView: "); getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE); View view = inflater.inflate(R.layout.sdrp_dialog, container); mDayOfWeekView = (TextView) view.findViewById(R.id.date_picker_header); mDayOfWeekViewEnd = (TextView) view.findViewById(R.id.date_picker_header_end); mMonthAndDayView = (LinearLayout) view.findViewById(R.id.date_picker_month_and_day); mMonthAndDayViewEnd = (LinearLayout) view.findViewById(R.id.date_picker_month_and_day_end); mMonthAndDayView.setOnClickListener(this); mMonthAndDayViewEnd.setOnClickListener(this); mSelectedMonthTextView = (TextView) view.findViewById(R.id.date_picker_month); mSelectedMonthTextViewEnd = (TextView) view.findViewById(R.id.date_picker_month_end); mSelectedDayTextView = (TextView) view.findViewById(R.id.date_picker_day); mSelectedDayTextViewEnd = (TextView) view.findViewById(R.id.date_picker_day_end); mYearView = (TextView) view.findViewById(R.id.date_picker_year); mYearViewEnd = (TextView) view.findViewById(R.id.date_picker_year_end); mYearView.setOnClickListener(this); mYearViewEnd.setOnClickListener(this); mDurationView = (LinearLayout) view.findViewById(R.id.date_picker_duration_layout); mDurationView.setOnClickListener(this); mDurationTextView = (TextView) view.findViewById(R.id.date_picker_duration_days); mDurationEditText = (EditText) view.findViewById(R.id.date_picker_duration_days_et); // disable soft keyboard popup when edittext is selected mDurationEditText.setRawInputType(InputType.TYPE_CLASS_TEXT); mDurationEditText.setTextIsSelectable(true); mDurationDayTextView = (TextView) view.findViewById(R.id.tv_duration_day); mDurationArrow = (TextView) view.findViewById(R.id.arrow_start); mDurationArrow.setOnClickListener(this); mDurationArrowEnd = (TextView) view.findViewById(R.id.arrow_end); mDurationArrowEnd.setOnClickListener(this); viewList = new ArrayList<>(); viewList.add(MONTH_AND_DAY_VIEW, mMonthAndDayView); viewList.add(YEAR_VIEW, mYearView);//from ww w . j av a 2 s .c o m viewList.add(MONTH_AND_DAY_VIEW_END, mMonthAndDayViewEnd); viewList.add(YEAR_VIEW_END, mYearViewEnd); viewList.add(DURATION_VIEW, mDurationView); int listPosition = -1; int listPositionOffset = 0; int listPositionEnd = -1; int listPositionOffsetEnd = 0; int currentView = MONTH_AND_DAY_VIEW; if (savedInstanceState != null) { mWeekStart = savedInstanceState.getInt(KEY_WEEK_START); mMinYear = savedInstanceState.getInt(KEY_YEAR_START); mMaxYear = savedInstanceState.getInt(KEY_YEAR_END); currentView = savedInstanceState.getInt(KEY_CURRENT_VIEW); listPosition = savedInstanceState.getInt(KEY_LIST_POSITION); listPositionOffset = savedInstanceState.getInt(KEY_LIST_POSITION_OFFSET); listPositionEnd = savedInstanceState.getInt(KEY_LIST_POSITION_END); listPositionOffsetEnd = savedInstanceState.getInt(KEY_LIST_POSITION_OFFSET_END); mMinDate = (Calendar) savedInstanceState.getSerializable(KEY_MIN_DATE); mMaxDate = (Calendar) savedInstanceState.getSerializable(KEY_MAX_DATE); mMinSelectableDate = (Calendar) savedInstanceState.getSerializable(KEY_MIN_DATE_SELECTABLE); highlightedDays = (Calendar[]) savedInstanceState.getSerializable(KEY_HIGHLIGHTED_DAYS); selectableDays = (Calendar[]) savedInstanceState.getSerializable(KEY_SELECTABLE_DAYS); mThemeDark = savedInstanceState.getBoolean(KEY_THEME_DARK); mAccentColor = savedInstanceState.getInt(KEY_ACCENT); mVibrate = savedInstanceState.getBoolean(KEY_VIBRATE); mDismissOnPause = savedInstanceState.getBoolean(KEY_DISMISS); } final Activity activity = getActivity(); mDayPickerView = new SimpleDayPickerView(activity, this); mYearPickerView = new YearPickerView(activity, this); mDayPickerViewEnd = new SimpleDayPickerView(activity, this); mYearPickerViewEnd = new YearPickerView(activity, this); mNumberPadView = new NumberPadView(activity, this); Resources res = getResources(); mDayPickerDescription = res.getString(R.string.mdtp_day_picker_description); mSelectDay = res.getString(R.string.mdtp_select_day); mYearPickerDescription = res.getString(R.string.mdtp_year_picker_description); mSelectYear = res.getString(R.string.mdtp_select_year); int bgColorResource = mThemeDark ? R.color.mdtp_date_picker_view_animator_dark_theme : R.color.mdtp_date_picker_view_animator; view.setBackgroundColor(activity.getResources().getColor(bgColorResource)); if (mThemeDark) { view.findViewById(R.id.hyphen).setBackgroundColor( activity.getResources().getColor(R.color.date_picker_selector_unselected_dark_theme)); Utils.setMultiTextColorList(activity.getResources().getColorStateList(R.color.sdrp_selector_dark), mDayOfWeekView, mDayOfWeekViewEnd, mSelectedMonthTextView, mSelectedMonthTextViewEnd, mSelectedDayTextView, mSelectedDayTextViewEnd, mYearView, mYearViewEnd, mDurationTextView, mDurationDayTextView, mDurationArrow, mDurationArrowEnd, mDurationEditText, (TextView) view.findViewById(R.id.tv_duration)); } mAnimator = (AccessibleDateAnimator) view.findViewById(R.id.animator); mAnimator.addView(mDayPickerView); mAnimator.addView(mYearPickerView); mAnimator.addView(mDayPickerViewEnd); mAnimator.addView(mYearPickerViewEnd); mAnimator.addView(mNumberPadView); mAnimator.setDateMillis(mCalendar.getTimeInMillis()); Animation animation = new AlphaAnimation(0.0f, 1.0f); animation.setDuration(ANIMATION_DURATION); mAnimator.setInAnimation(animation); Animation animation2 = new AlphaAnimation(1.0f, 0.0f); animation2.setDuration(ANIMATION_DURATION); mAnimator.setOutAnimation(animation2); Button okButton = (Button) view.findViewById(R.id.ok); okButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tryVibrate(); if (mCallBack != null) { mCallBack.onDateRangeSet(SmoothDateRangePickerFragment.this, mCalendar.get(Calendar.YEAR), mCalendar.get(Calendar.MONTH), mCalendar.get(Calendar.DAY_OF_MONTH), mCalendarEnd.get(Calendar.YEAR), mCalendarEnd.get(Calendar.MONTH), mCalendarEnd.get(Calendar.DAY_OF_MONTH)); } dismiss(); } }); okButton.setTypeface(TypefaceHelper.get(activity, "Roboto-Medium")); Button cancelButton = (Button) view.findViewById(R.id.cancel); cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tryVibrate(); if (getDialog() != null) getDialog().cancel(); } }); cancelButton.setTypeface(TypefaceHelper.get(activity, "Roboto-Medium")); cancelButton.setVisibility(isCancelable() ? View.VISIBLE : View.GONE); //If an accent color has not been set manually, try and get it from the context if (mAccentColor == -1) { int accentColor = Utils.getAccentColorFromThemeIfAvailable(getActivity()); if (accentColor != -1) { mAccentColor = accentColor; } } if (mAccentColor != -1) { if (mDayOfWeekView != null) mDayOfWeekView.setBackgroundColor(mAccentColor); if (mDayOfWeekViewEnd != null) mDayOfWeekViewEnd.setBackgroundColor(mAccentColor); view.findViewById(R.id.layout_container).setBackgroundColor(mAccentColor); view.findViewById(R.id.day_picker_selected_date_layout).setBackgroundColor(mAccentColor); view.findViewById(R.id.day_picker_selected_date_layout_end).setBackgroundColor(mAccentColor); mDurationView.setBackgroundColor(mAccentColor); mDurationEditText.setHighlightColor(Utils.darkenColor(mAccentColor)); mDurationEditText.getBackground().setColorFilter(Utils.darkenColor(mAccentColor), PorterDuff.Mode.SRC_ATOP); okButton.setTextColor(mAccentColor); cancelButton.setTextColor(mAccentColor); mYearPickerView.setAccentColor(mAccentColor); mDayPickerView.setAccentColor(mAccentColor); mYearPickerViewEnd.setAccentColor(mAccentColor); mDayPickerViewEnd.setAccentColor(mAccentColor); } updateDisplay(false); setCurrentView(currentView); if (listPosition != -1) { if (currentView == MONTH_AND_DAY_VIEW) { mDayPickerView.postSetSelection(listPosition); } else if (currentView == YEAR_VIEW) { mYearPickerView.postSetSelectionFromTop(listPosition, listPositionOffset); } } if (listPositionEnd != -1) { if (currentView == MONTH_AND_DAY_VIEW_END) { mDayPickerViewEnd.postSetSelection(listPositionEnd); } else if (currentView == YEAR_VIEW_END) { mYearPickerViewEnd.postSetSelectionFromTop(listPositionEnd, listPositionOffsetEnd); } } mHapticFeedbackController = new HapticFeedbackController(activity); return view; }