List of usage examples for android.os Bundle getParcelable
@Nullable public <T extends Parcelable> T getParcelable(@Nullable String key)
From source file:com.customdatepicker.date.DatePickerDialog.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { int listPosition = -1; int listPositionOffset = 0; int currentView = mDefaultView; if (savedInstanceState != null) { mWeekStart = savedInstanceState.getInt(KEY_WEEK_START); currentView = savedInstanceState.getInt(KEY_CURRENT_VIEW); listPosition = savedInstanceState.getInt(KEY_LIST_POSITION); listPositionOffset = savedInstanceState.getInt(KEY_LIST_POSITION_OFFSET); //noinspection unchecked highlightedDays = (HashSet<Calendar>) savedInstanceState.getSerializable(KEY_HIGHLIGHTED_DAYS); 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); mAutoDismiss = savedInstanceState.getBoolean(KEY_AUTO_DISMISS); mTitle = savedInstanceState.getString(KEY_TITLE); 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); mTimezone = (TimeZone) savedInstanceState.getSerializable(KEY_TIMEZONE); mDateRangeLimiter = savedInstanceState.getParcelable(KEY_DATERANGELIMITER); /*/* ww w.j a va 2s . c o m*/ If the user supplied a custom limiter, we need to create a new default one to prevent null pointer exceptions on the configuration methods If the user did not supply a custom limiter we need to ensure both mDefaultLimiter and mDateRangeLimiter are the same reference, so that the config methods actually ffect the behaviour of the picker (in the unlikely event the user reconfigures the picker when it is shown) */ if (mDateRangeLimiter instanceof DefaultDateRangeLimiter) { mDefaultLimiter = (DefaultDateRangeLimiter) mDateRangeLimiter; } else { mDefaultLimiter = new DefaultDateRangeLimiter(); } } mDefaultLimiter.setController(this); int viewRes = mVersion == Version.VERSION_1 ? R.layout.mdtp_date_picker_dialog : R.layout.mdtp_date_picker_dialog_v2; View view = inflater.inflate(viewRes, container, false); // All options have been set at this point: round the initial selection if necessary mCalendar = mDateRangeLimiter.setToNearestDate(mCalendar); mDatePickerHeaderView = (TextView) view.findViewById(R.id.mdtp_date_picker_header); mImageViewLeft = (ImageView) view.findViewById(R.id.imageViewLeft); mImageViewRight = (ImageView) view.findViewById(R.id.imageViewRight); mMonthAndDayView = (LinearLayout) view.findViewById(R.id.mdtp_date_picker_month_and_day); mMonthAndDayView.setOnClickListener(this); mSelectedMonthTextView = (TextView) view.findViewById(R.id.mdtp_date_picker_month); mSelectedDayTextView = (TextView) view.findViewById(R.id.mdtp_date_picker_day); mYearView = (TextView) view.findViewById(R.id.mdtp_date_picker_year); mYearView.setOnClickListener(this); mImageViewLeft.setOnClickListener(this); mImageViewRight.setOnClickListener(this); final Activity activity = getActivity(); mDayPickerView = new SimpleDayPickerView(activity, this); mYearPickerView = new YearPickerView(activity, this); // if theme mode has not been set by java code, check if it is specified in Style.xml if (!mThemeDarkChanged) { mThemeDark = Utils.isDarkTheme(activity, mThemeDark); } 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(ContextCompat.getColor(activity, bgColorResource)); mAnimator = (AccessibleDateAnimator) view.findViewById(R.id.mdtp_animator); 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); Button okButton = (Button) view.findViewById(R.id.mdtp_ok); okButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tryVibrate(); notifyOnDateListener(); dismiss(); } }); okButton.setTypeface(TypefaceHelper.get(activity, "Roboto-Medium")); if (mOkString != null) okButton.setText(mOkString); else okButton.setText(mOkResid); Button cancelButton = (Button) view.findViewById(R.id.mdtp_cancel); cancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tryVibrate(); if (getDialog() != null) getDialog().cancel(); } }); cancelButton.setTypeface(TypefaceHelper.get(activity, "Roboto-Medium")); if (mCancelString != null) cancelButton.setText(mCancelString); else cancelButton.setText(mCancelResid); cancelButton.setVisibility(isCancelable() ? View.VISIBLE : View.GONE); // If an accent color has not been set manually, get it from the context if (mAccentColor == -1) { mAccentColor = Utils.getAccentColorFromThemeIfAvailable(getActivity()); } if (mDatePickerHeaderView != null) mDatePickerHeaderView.setBackgroundColor(Utils.darkenColor(mAccentColor)); view.findViewById(R.id.mdtp_day_picker_selected_date_layout).setBackgroundColor(mAccentColor); // Buttons can have a different color if (mOkColor != -1) okButton.setTextColor(mOkColor); else okButton.setTextColor(mAccentColor); if (mCancelColor != -1) cancelButton.setTextColor(mCancelColor); else cancelButton.setTextColor(mAccentColor); if (getDialog() == null) { view.findViewById(R.id.mdtp_done_background).setVisibility(View.GONE); } 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); } } mHapticFeedbackController = new HapticFeedbackController(activity); return view; }
From source file:com.android.messaging.ui.conversationlist.ConversationListFragment.java
/** * {@inheritDoc} from Fragment//from w w w . j ava 2 s . co m */ @Override public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) { final ViewGroup rootView = (ViewGroup) inflater.inflate(R.layout.conversation_list_fragment, container, false); mRecyclerView = (RecyclerView) rootView.findViewById(android.R.id.list); mEmptyListMessageView = (ListEmptyView) rootView.findViewById(R.id.no_conversations_view); mEmptyListMessageView.setImageHint(R.drawable.ic_oobe_conv_list); // The default behavior for default layout param generation by LinearLayoutManager is to // provide width and height of WRAP_CONTENT, but this is not desirable for // ConversationListFragment; the view in each row should be a width of MATCH_PARENT so that // the entire row is tappable. final Activity activity = getActivity(); final LinearLayoutManager manager = new LinearLayoutManager(activity) { @Override public RecyclerView.LayoutParams generateDefaultLayoutParams() { return new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); } }; mRecyclerView.setLayoutManager(manager); mRecyclerView.setHasFixedSize(true); mRecyclerView.setAdapter(mAdapter); mRecyclerView.setOnScrollListener(new RecyclerView.OnScrollListener() { int mCurrentState = AbsListView.OnScrollListener.SCROLL_STATE_IDLE; @Override public void onScrolled(final RecyclerView recyclerView, final int dx, final int dy) { if (mCurrentState == AbsListView.OnScrollListener.SCROLL_STATE_TOUCH_SCROLL || mCurrentState == AbsListView.OnScrollListener.SCROLL_STATE_FLING) { ImeUtil.get().hideImeKeyboard(getActivity(), mRecyclerView); } if (isScrolledToFirstConversation()) { setScrolledToNewestConversationIfNeeded(); } else { mListBinding.getData().setScrolledToNewestConversation(false); } } @Override public void onScrollStateChanged(final RecyclerView recyclerView, final int newState) { mCurrentState = newState; } }); mRecyclerView.addOnItemTouchListener(new ConversationListSwipeHelper(mRecyclerView)); if (savedInstanceState != null) { mListState = savedInstanceState.getParcelable(SAVED_INSTANCE_STATE_LIST_VIEW_STATE_KEY); } mStartNewConversationButton = (ImageView) rootView.findViewById(R.id.start_new_conversation_button); if (mArchiveMode) { mStartNewConversationButton.setVisibility(View.GONE); } else { mStartNewConversationButton.setVisibility(View.VISIBLE); mStartNewConversationButton.setOnClickListener(new OnClickListener() { @Override public void onClick(final View clickView) { mHost.onCreateConversationClick(); } }); } ViewCompat.setTransitionName(mStartNewConversationButton, BugleAnimationTags.TAG_FABICON); // The root view has a non-null background, which by default is deemed by the framework // to be a "transition group," where all child views are animated together during an // activity transition. However, we want each individual items in the recycler view to // show explode animation themselves, so we explicitly tag the root view to be a non-group. ViewGroupCompat.setTransitionGroup(rootView, false); setHasOptionsMenu(true); return rootView; }
From source file:com.android.settings.HWSettings.java
@Override protected void onCreate(Bundle savedInstanceState) { mVoiceCapable = getResources().getBoolean(com.android.internal.R.bool.config_voice_capable); if (getIntent().hasExtra(EXTRA_UI_OPTIONS)) { getWindow().setUiOptions(getIntent().getIntExtra(EXTRA_UI_OPTIONS, 0)); }/*from w w w .ja v a 2 s . com*/ mAuthenticatorHelper = new AuthenticatorHelper(); mAuthenticatorHelper.updateAuthDescriptions(this); mAuthenticatorHelper.onAccountsUpdated(this, null); mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE, Context.MODE_PRIVATE); getMetaData(); mInLocalHeaderSwitch = true; super.onCreate(savedInstanceState); setContentView(R.layout.settings_main); mInLocalHeaderSwitch = false; /** * SPRD:Optimization to erase the animation on click. @{ */ ListView list = getListView(); list.setSelector(R.drawable.list_selector_holo_dark); /** @} */ if (!onIsHidingHeaders() && onIsMultiPane()) { highlightHeader(mTopLevelHeaderId); // Force the title so that it doesn't get overridden by a direct launch of // a specific settings screen. setTitle(R.string.settings_label); } // Retrieve any saved state if (savedInstanceState != null) { mCurrentHeader = savedInstanceState.getParcelable(SAVE_KEY_CURRENT_HEADER); mParentHeader = savedInstanceState.getParcelable(SAVE_KEY_PARENT_HEADER); if (HW_SETTINGS) { //wangkaifeng tab settings curTabIndex = savedInstanceState.getInt(SAVE_KEY_CURRENT_TAB); } } // If the current header was saved, switch to it if (savedInstanceState != null && mCurrentHeader != null) { //switchToHeaderLocal(mCurrentHeader); showBreadCrumbs(mCurrentHeader.title, null); } if (mParentHeader != null) { setParentTitle(mParentHeader.title, null, new OnClickListener() { @Override public void onClick(View v) { switchToParent(mParentHeader.fragment); } }); } // Override up navigation for multi-pane, since we handle it in the fragment breadcrumbs if (onIsMultiPane()) { getActionBar().setDisplayHomeAsUpEnabled(false); getActionBar().setHomeButtonEnabled(false); } /* SPRD: add for tab style @{ */ mInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); /* @} */ /* hw settings {@ */ if (HW_SETTINGS) { //wangkaifeng tab settings createFragments(); if (this.toString().contains(".HWSettings@")) { mActionBar = getActionBar(); int tabHeight = 80;//(int) getResources().getDimensionPixelSize(R.dimen.universe_ui_tab_height); //revo lyq int TYPELCD = SystemProperties.getInt("qemu.sf.lcd_density", SystemProperties.getInt("ro.sf.lcd_density", 240)); if (TYPELCD == 160) { tabHeight = 52; } mActionBar.setAlternativeTabStyle(false); mActionBar.setTabHeight(tabHeight); setupGeneral(mActionBar); setupAll(mActionBar); mActionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS); mActionBar.setDisplayShowTitleEnabled(false); mActionBar.setDisplayShowHomeEnabled(false); } } /* @} */ //liangbo add 20141231 if (FeatureOption.PRJ_FEATURE_SHOW_MENU_FOR_DEVOLOPMENT_SETTINGS) { getSharedPreferences(DevelopmentSettings.PREF_FILE, Context.MODE_PRIVATE).edit() .putBoolean(DevelopmentSettings.PREF_SHOW, true).apply(); } }
From source file:com.krayzk9s.imgurholo.ui.SingleImageFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); final ImgurHoloActivity activity = (ImgurHoloActivity) getActivity(); final SharedPreferences settings = activity.getApiCall().settings; sort = settings.getString("CommentSort", "Best"); boolean newData = true; if (commentData != null) { newData = false;//from w w w . ja v a2 s. com } mainView = inflater.inflate(R.layout.single_image_layout, container, false); String[] mMenuList = getResources().getStringArray(R.array.emptyList); if (commentAdapter == null) commentAdapter = new CommentAdapter(mainView.getContext()); commentLayout = (ListView) mainView.findViewById(R.id.comment_thread); commentLayout.setChoiceMode(ListView.CHOICE_MODE_SINGLE); if (settings.getString("theme", MainActivity.HOLO_LIGHT).equals(MainActivity.HOLO_LIGHT)) imageLayoutView = (LinearLayout) View.inflate(getActivity(), R.layout.image_view, null); else imageLayoutView = (LinearLayout) View.inflate(getActivity(), R.layout.dark_image_view, null); mPullToRefreshLayout = (PullToRefreshLayout) mainView.findViewById(R.id.ptr_layout); ActionBarPullToRefresh.from(getActivity()) // Mark All Children as pullable .allChildrenArePullable() // Set the OnRefreshListener .listener(this) // Finally commit the setup to our PullToRefreshLayout .setup(mPullToRefreshLayout); if (savedInstanceState != null && newData) { imageData = savedInstanceState.getParcelable("imageData"); inGallery = savedInstanceState.getBoolean("inGallery"); } LinearLayout layout = (LinearLayout) imageLayoutView.findViewById(R.id.image_buttons); TextView imageDetails = (TextView) imageLayoutView.findViewById(R.id.single_image_details); layout.setVisibility(View.VISIBLE); ImageButton imageFullscreen = (ImageButton) imageLayoutView.findViewById(R.id.fullscreen); imageUpvote = (ImageButton) imageLayoutView.findViewById(R.id.rating_good); imageDownvote = (ImageButton) imageLayoutView.findViewById(R.id.rating_bad); ImageButton imageFavorite = (ImageButton) imageLayoutView.findViewById(R.id.rating_favorite); imageComment = (ImageButton) imageLayoutView.findViewById(R.id.comment); ImageButton imageUser = (ImageButton) imageLayoutView.findViewById(R.id.user); imageScore = (TextView) imageLayoutView.findViewById(R.id.single_image_score); TextView imageInfo = (TextView) imageLayoutView.findViewById(R.id.single_image_info); Log.d("imageData", imageData.getJSONObject().toString()); if (imageData.getJSONObject().has("ups")) { imageUpvote.setVisibility(View.VISIBLE); imageDownvote.setVisibility(View.VISIBLE); imageScore.setVisibility(View.VISIBLE); imageComment.setVisibility(View.VISIBLE); ImageUtils.updateImageFont(imageData, imageScore); } imageInfo.setVisibility(View.VISIBLE); ImageUtils.updateInfoFont(imageData, imageInfo); imageUser.setVisibility(View.VISIBLE); imageFavorite.setVisibility(View.VISIBLE); try { if (!imageData.getJSONObject().has("account_url") || imageData.getJSONObject().getString("account_url").equals("null") || imageData.getJSONObject().getString("account_url").equals("[deleted]")) imageUser.setVisibility(View.GONE); if (!imageData.getJSONObject().has("vote")) { imageUpvote.setVisibility(View.GONE); imageDownvote.setVisibility(View.GONE); } else { if (imageData.getJSONObject().getString("vote") != null && imageData.getJSONObject().getString("vote").equals("up")) imageUpvote.setImageResource(R.drawable.green_rating_good); else if (imageData.getJSONObject().getString("vote") != null && imageData.getJSONObject().getString("vote").equals("down")) imageDownvote.setImageResource(R.drawable.red_rating_bad); } if (imageData.getJSONObject().getString("favorite") != null && imageData.getJSONObject().getBoolean("favorite")) imageFavorite.setImageResource(R.drawable.green_rating_favorite); } catch (JSONException e) { Log.e("Error!", e.toString()); } imageFavorite.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.favoriteImage(singleImageFragment, imageData, (ImageButton) view, activity.getApiCall()); } }); imageUser.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.gotoUser(singleImageFragment, imageData); } }); imageComment.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Activity activity = getActivity(); final EditText newBody = new EditText(activity); newBody.setHint(R.string.body_hint_body); newBody.setLines(3); final TextView characterCount = new TextView(activity); characterCount.setText("140"); LinearLayout commentReplyLayout = new LinearLayout(activity); newBody.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence charSequence, int i, int i2, int i3) { // } @Override public void onTextChanged(CharSequence charSequence, int i, int i2, int i3) { characterCount.setText(String.valueOf(140 - charSequence.length())); } @Override public void afterTextChanged(Editable editable) { for (int i = editable.length(); i > 0; i--) { if (editable.subSequence(i - 1, i).toString().equals("\n")) editable.replace(i - 1, i, ""); } } }); commentReplyLayout.setOrientation(LinearLayout.VERTICAL); commentReplyLayout.addView(newBody); commentReplyLayout.addView(characterCount); new AlertDialog.Builder(activity).setTitle(R.string.dialog_comment_on_image_title) .setView(commentReplyLayout) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { if (newBody.getText() != null && newBody.getText().toString().length() < 141) { HashMap<String, Object> commentMap = new HashMap<String, Object>(); try { commentMap.put("comment", newBody.getText().toString()); commentMap.put("image_id", imageData.getJSONObject().getString("id")); Fetcher fetcher = new Fetcher(singleImageFragment, "3/comment/", ApiCall.POST, commentMap, ((ImgurHoloActivity) getActivity()).getApiCall(), POSTCOMMENT); fetcher.execute(); } catch (JSONException e) { Log.e("Error!", e.toString()); } } } }).setNegativeButton(R.string.dialog_answer_cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); } }); imageUpvote.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.upVote(singleImageFragment, imageData, imageUpvote, imageDownvote, activity.getApiCall()); ImageUtils.updateImageFont(imageData, imageScore); } }); imageDownvote.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.downVote(singleImageFragment, imageData, imageUpvote, imageDownvote, activity.getApiCall()); ImageUtils.updateImageFont(imageData, imageScore); } }); if (popupWindow != null) { popupWindow.dismiss(); } popupWindow = new PopupWindow(); imageFullscreen.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { ImageUtils.fullscreen(singleImageFragment, imageData, popupWindow, mainView); } }); ArrayAdapter<String> tempAdapter = new ArrayAdapter<String>(mainView.getContext(), R.layout.drawer_list_item, mMenuList); Log.d("URI", "YO I'M IN YOUR SINGLE FRAGMENT gallery:" + inGallery); imageView = (ImageView) imageLayoutView.findViewById(R.id.single_image_view); loadImage(); TextView imageTitle = (TextView) imageLayoutView.findViewById(R.id.single_image_title); TextView imageDescription = (TextView) imageLayoutView.findViewById(R.id.single_image_description); try { String size = String .valueOf(NumberFormat.getIntegerInstance() .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_WIDTH))) + "x" + NumberFormat.getIntegerInstance() .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_HEIGHT)) + " (" + NumberFormat.getIntegerInstance() .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_SIZE)) + "B)"; String initial = imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TYPE) + " " + Html.fromHtml("•") + " " + size + " " + Html.fromHtml("•") + " " + "Views: " + NumberFormat.getIntegerInstance() .format(imageData.getJSONObject().getInt(ImgurHoloActivity.IMAGE_DATA_VIEWS)); imageDetails.setText(initial); Log.d("imagedata", imageData.getJSONObject().toString()); if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE).equals("null")) imageTitle.setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE)); else imageTitle.setVisibility(View.GONE); if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION).equals("null")) { imageDescription .setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION)); imageDescription.setVisibility(View.VISIBLE); } else imageDescription.setVisibility(View.GONE); commentLayout.addHeaderView(imageLayoutView); commentLayout.setAdapter(tempAdapter); } catch (JSONException e) { Log.e("Text Error!", e.toString()); } if ((savedInstanceState == null || commentData == null) && newData) { commentData = new JSONParcelable(); getComments(); commentLayout.setAdapter(commentAdapter); } else if (newData) { commentArray = savedInstanceState.getParcelableArrayList("commentData"); commentAdapter.addAll(commentArray); commentLayout.setAdapter(commentAdapter); commentAdapter.notifyDataSetChanged(); } else if (commentArray != null) { commentAdapter.addAll(commentArray); commentLayout.setAdapter(commentAdapter); commentAdapter.notifyDataSetChanged(); } return mainView; }
From source file:com.andrewshu.android.reddit.threads.ThreadsListActivity.java
/** * Called when the activity starts up. Do activity initialization * here, not in a constructor./*from www. j ava2 s. com*/ * * @see Activity#onCreate */ @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); CookieSyncManager.createInstance(getApplicationContext()); mSettings.loadRedditPreferences(getApplicationContext(), mClient); setRequestedOrientation(mSettings.getRotation()); setTheme(mSettings.getTheme()); requestWindowFeature(Window.FEATURE_PROGRESS); requestWindowFeature(Window.FEATURE_INDETERMINATE_PROGRESS); setContentView(R.layout.threads_list_content); registerForContextMenu(getListView()); if (savedInstanceState != null) { if (Constants.LOGGING) Log.d(TAG, "using savedInstanceState"); mSubreddit = savedInstanceState.getString(Constants.SUBREDDIT_KEY); if (mSubreddit == null) mSubreddit = mSettings.getHomepage(); mAfter = savedInstanceState.getString(Constants.AFTER_KEY); mBefore = savedInstanceState.getString(Constants.BEFORE_KEY); mCount = savedInstanceState.getInt(Constants.THREAD_COUNT_KEY); mLastAfter = savedInstanceState.getString(Constants.LAST_AFTER_KEY); mLastBefore = savedInstanceState.getString(Constants.LAST_BEFORE_KEY); mLastCount = savedInstanceState.getInt(Constants.THREAD_LAST_COUNT_KEY); mSortByUrl = savedInstanceState.getString(Constants.ThreadsSort.SORT_BY_KEY); mJumpToThreadId = savedInstanceState.getString(Constants.JUMP_TO_THREAD_ID_KEY); mVoteTargetThing = savedInstanceState.getParcelable(Constants.VOTE_TARGET_THING_INFO_KEY); // try to restore mThreadsList using getLastNonConfigurationInstance() // (separate function to avoid a compiler warning casting ArrayList<ThingInfo> restoreLastNonConfigurationInstance(); if (mThreadsList == null) { // Load previous view of threads if (mLastAfter != null) { new MyDownloadThreadsTask(mSubreddit, mLastAfter, null, mLastCount).execute(); } else if (mLastBefore != null) { new MyDownloadThreadsTask(mSubreddit, null, mLastBefore, mLastCount).execute(); } else { new MyDownloadThreadsTask(mSubreddit).execute(); } } else { // Orientation change. Use prior instance. resetUI(new ThreadsListAdapter(this, mThreadsList)); if (Constants.FRONTPAGE_STRING.equals(mSubreddit)) setTitle("reddit.com: what's new online!"); else setTitle("/r/" + mSubreddit.trim()); } } // Handle subreddit Uri passed via Intent else if (getIntent().getData() != null) { Matcher redditContextMatcher = REDDIT_PATH_PATTERN.matcher(getIntent().getData().getPath()); if (redditContextMatcher.matches()) { new MyDownloadThreadsTask(redditContextMatcher.group(1)).execute(); } else { new MyDownloadThreadsTask(mSettings.getHomepage()).execute(); } } // No subreddit specified by Intent, so load the user's home reddit else { new MyDownloadThreadsTask(mSettings.getHomepage()).execute(); } }
From source file:com.android.mail.ui.ConversationListFragment.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedState) { View rootView = inflater.inflate(R.layout.conversation_list, null); mEmptyView = (ConversationListEmptyView) rootView.findViewById(R.id.empty_view); mSecurityHoldView = rootView.findViewById(R.id.security_hold_view); mSecurityHoldText = (TextView) rootView.findViewById(R.id.security_hold_text); mSecurityHoldButton = rootView.findViewById(R.id.security_hold_button); mSecurityHoldButton.setOnClickListener(this); mLoadingView = rootView.findViewById(R.id.conversation_list_loading_view); mListView = (SwipeableListView) rootView.findViewById(R.id.conversation_list_view); mListView.setHeaderDividersEnabled(false); mListView.setOnItemLongClickListener(this); mListView.enableSwipe(mAccount.supportsCapability(AccountCapabilities.UNDO)); mListView.setListItemSwipedListener(this); mListView.setSwipeListener(this); mListView.setOnKeyListener(this); mListView.setOnItemClickListener(this); // For tablets, the default left focus is the mini-drawer if (mTabletDevice && mNextFocusStartId == 0) { mNextFocusStartId = R.id.mini_drawer; }//from w ww . j ava2s . c om setNextFocusStartOnList(); // enable animateOnLayout (equivalent of setLayoutTransition) only for >=JB (b/14302062) if (Utils.isRunningJellybeanOrLater()) { ((ViewGroup) rootView.findViewById(R.id.conversation_list_parent_frame)) .setLayoutTransition(new LayoutTransition()); } // By default let's show the list view showListView(); if (savedState != null && savedState.containsKey(LIST_STATE_KEY)) { mListView.onRestoreInstanceState(savedState.getParcelable(LIST_STATE_KEY)); } mSwipeRefreshWidget = (MailSwipeRefreshLayout) rootView.findViewById(R.id.swipe_refresh_widget); mSwipeRefreshWidget.setColorScheme(R.color.swipe_refresh_color1, R.color.swipe_refresh_color2, R.color.swipe_refresh_color3, R.color.swipe_refresh_color4); mSwipeRefreshWidget.setOnRefreshListener(this); mSwipeRefreshWidget.setScrollableChild(mListView); return rootView; }
From source file:com.android.mail.compose.ComposeActivity.java
private static void closeOpenedAttachmentFds(final SendOrSaveMessage sendOrSaveMessage) { final Bundle openedFds = sendOrSaveMessage.attachmentFds(); if (openedFds != null) { final Set<String> keys = openedFds.keySet(); for (final String key : keys) { final ParcelFileDescriptor fd = openedFds.getParcelable(key); if (fd != null) { try { fd.close();//from ww w.j a v a 2 s .co m } catch (IOException e) { // Do nothing } } } } }
From source file:com.dycody.android.idealnote.DetailFragment.java
@Override public void onActivityCreated(Bundle savedInstanceState) { super.onActivityCreated(savedInstanceState); mainActivity = (MainActivity) getActivity(); prefs = mainActivity.prefs;//from w ww . j av a2 s. c om mainActivity.getSupportActionBar().setDisplayShowTitleEnabled(false); mainActivity.getToolbar().setNavigationOnClickListener(v -> navigateUp()); // Force the navigation drawer to stay opened if tablet mode is on, otherwise has to stay closed if (NavigationDrawerFragment.isDoublePanelActive()) { mainActivity.getDrawerLayout().setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_OPEN); } else { mainActivity.getDrawerLayout().setDrawerLockMode(DrawerLayout.LOCK_MODE_LOCKED_CLOSED); } // Restored temp note after orientation change if (savedInstanceState != null) { noteTmp = savedInstanceState.getParcelable("noteTmp"); note = savedInstanceState.getParcelable("note"); noteOriginal = savedInstanceState.getParcelable("noteOriginal"); attachmentUri = savedInstanceState.getParcelable("attachmentUri"); orientationChanged = savedInstanceState.getBoolean("orientationChanged"); } // Added the sketched image if present returning from SketchFragment if (mainActivity.sketchUri != null) { Attachment mAttachment = new Attachment(mainActivity.sketchUri, Constants.MIME_TYPE_SKETCH); addAttachment(mAttachment); mainActivity.sketchUri = null; // Removes previous version of edited image if (sketchEdited != null) { noteTmp.getAttachmentsList().remove(sketchEdited); sketchEdited = null; } } init(); setHasOptionsMenu(true); setRetainInstance(false); }
From source file:com.android.settings.Settings.java
@Override protected void onCreate(Bundle savedInstanceState) { mVoiceCapable = getResources().getBoolean(com.android.internal.R.bool.config_voice_capable); if (getIntent().hasExtra(EXTRA_UI_OPTIONS)) { getWindow().setUiOptions(getIntent().getIntExtra(EXTRA_UI_OPTIONS, 0)); }//from w w w. j a v a2s .c o m mAuthenticatorHelper = new AuthenticatorHelper(); mAuthenticatorHelper.updateAuthDescriptions(this); mAuthenticatorHelper.onAccountsUpdated(this, null); mDevelopmentPreferences = getSharedPreferences(DevelopmentSettings.PREF_FILE, Context.MODE_PRIVATE); getMetaData(); mInLocalHeaderSwitch = true; super.onCreate(savedInstanceState); mInLocalHeaderSwitch = false; /** * SPRD:Optimization to erase the animation on click. @{ */ ListView list = getListView(); list.setSelector(R.drawable.list_selector_holo_dark); //revo lyq 2014 for advan settings if (FeatureOption.PRJ_FEATURE_MULTI_PRJ_CUSTOMER_ADVAN_BASE) { list.is_no_padding = true; } /** @} */ if (!onIsHidingHeaders() && onIsMultiPane()) { highlightHeader(mTopLevelHeaderId); // Force the title so that it doesn't get overridden by a direct launch of // a specific settings screen. setTitle(R.string.settings_label); } // Retrieve any saved state if (savedInstanceState != null) { mCurrentHeader = savedInstanceState.getParcelable(SAVE_KEY_CURRENT_HEADER); mParentHeader = savedInstanceState.getParcelable(SAVE_KEY_PARENT_HEADER); } // If the current header was saved, switch to it if (savedInstanceState != null && mCurrentHeader != null) { //switchToHeaderLocal(mCurrentHeader); showBreadCrumbs(mCurrentHeader.title, null); } if (mParentHeader != null) { setParentTitle(mParentHeader.title, null, new OnClickListener() { @Override public void onClick(View v) { switchToParent(mParentHeader.fragment); } }); } // Override up navigation for multi-pane, since we handle it in the fragment breadcrumbs if (onIsMultiPane()) { getActionBar().setDisplayHomeAsUpEnabled(false); getActionBar().setHomeButtonEnabled(false); } /* SPRD: add for tab style @{ */ mInflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (UNIVERSEUI_SUPPORT) { if (this.getClass().equals(Settings.class)) { int index = getIntent().getIntExtra("tab_index", mCurrentTabIndex); setupTab(); chooseTab(index); } } if (FeatureOption.PRJ_FEATURE_MULTI_PRJ_TIANRUIXIANG_BASE || FeatureOption.PRJ_FEATURE_SHOW_MENU_FOR_DEVOLOPMENT_SETTINGS) { getSharedPreferences(DevelopmentSettings.PREF_FILE, Context.MODE_PRIVATE).edit() .putBoolean(DevelopmentSettings.PREF_SHOW, true).apply(); } /* @} */ }
From source file:com.bitants.wally.activities.ImageDetailsActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_image_details); setToolbar((Toolbar) findViewById(R.id.toolbar)); if (getToolbar() != null) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { getWindow().setStatusBarColor(Color.TRANSPARENT); getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN); }/*w w w.jav a 2 s . c om*/ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { getToolbar().setPadding(0, getStatusBarHeight(), 0, 0); } getSupportActionBar().setDisplayHomeAsUpEnabled(true); getSupportActionBar().setTitle(""); } final Intent intent = getIntent(); String action = intent.getAction(); if (Intent.ACTION_VIEW.equals(action)) { pageUri = Uri.parse(intent.getDataString()); if ("wally".equalsIgnoreCase(pageUri.getScheme())) { pageUri = pageUri.buildUpon().scheme("http").build(); } } setupViews(); setupHandlers(); Size size = new Size(16, 9); if (intent.hasExtra(INTENT_EXTRA_IMAGE)) { final Image image = intent.getParcelableExtra(INTENT_EXTRA_IMAGE); final Bitmap thumbBitmap = WallyApplication.getBitmapThumb(); if (thumbBitmap != null) { size = fitToWidthAndKeepRatio(image.getWidth(), image.getHeight()); imageSize = size; photoView.getLayoutParams().width = size.getWidth(); photoView.getLayoutParams().height = size.getHeight(); Bitmap blurBitMap; try { blurBitMap = Blur.apply(imageHolder.getContext(), thumbBitmap); } catch (ArrayIndexOutOfBoundsException e) { //Blur couldn't be applied. Show regular thumbnail instead. blurBitMap = thumbBitmap; } photoView.setImageBitmap(blurBitMap); } } setupPaddings(size, false); if (savedInstanceState == null) { getPage(pageUri.toString()); } else if (savedInstanceState.containsKey(STATE_IMAGE_PAGE)) { imagePage = savedInstanceState.getParcelable(STATE_IMAGE_PAGE); } if (imagePage != null) { Message msgObj = uiHandler.obtainMessage(); msgObj.what = MSG_PAGE_FETCHED; msgObj.obj = imagePage; uiHandler.sendMessage(msgObj); } else { getPage(pageUri.toString()); } }