List of usage examples for android.view View setBackgroundColor
@RemotableViewMethod public void setBackgroundColor(@ColorInt int color)
From source file:com.saarang.samples.apps.iosched.ui.SessionsFragment.java
@Override public void bindCollectionItemView(Context context, View view, int groupId, int indexInGroup, int dataIndex, Object tag) {/* w w w . jav a 2s. co m*/ if (mCursor == null || !mCursor.moveToPosition(dataIndex)) { LOGW(TAG, "Can't bind collection view item, dataIndex=" + dataIndex + (mCursor == null ? ": cursor is null" : ": bad data index.")); return; } final String sessionId = mCursor.getString(SessionsQuery.SESSION_ID); if (sessionId == null) { return; } // first, read session info from cursor and put it in convenience variables final String sessionTitle = mCursor.getString(SessionsQuery.TITLE); final String speakerNames = mCursor.getString(SessionsQuery.SPEAKER_NAMES); final String sessionAbstract = mCursor.getString(SessionsQuery.ABSTRACT); final long sessionStart = mCursor.getLong(SessionsQuery.SESSION_START); final long sessionEnd = mCursor.getLong(SessionsQuery.SESSION_END); final String roomName = mCursor.getString(SessionsQuery.ROOM_NAME); int sessionColor = mCursor.getInt(SessionsQuery.COLOR); sessionColor = sessionColor == 0 ? getResources().getColor(com.saarang.samples.apps.iosched.R.color.default_session_color) : sessionColor; int darkSessionColor = 0; final String snippet = mIsSearchCursor ? mCursor.getString(SessionsQuery.SNIPPET) : null; final Spannable styledSnippet = mIsSearchCursor ? UIUtils.buildStyledSnippet(snippet) : null; final boolean starred = mCursor.getInt(SessionsQuery.IN_MY_SCHEDULE) != 0; final String[] tags = mCursor.getString(SessionsQuery.TAGS).split(","); // now let's compute a few pieces of information from the data, which we will use // later to decide what to render where final boolean hasLivestream = !TextUtils.isEmpty(mCursor.getString(SessionsQuery.LIVESTREAM_URL)); final long now = UIUtils.getCurrentTime(context); final boolean happeningNow = now >= sessionStart && now <= sessionEnd; // text that says "LIVE" if session is live, or empty if session is not live final String liveNowText = hasLivestream ? " " + UIUtils.getLiveBadgeText(context, sessionStart, sessionEnd) : ""; // get reference to all the views in the layout we will need final TextView titleView = (TextView) view .findViewById(com.saarang.samples.apps.iosched.R.id.session_title); final TextView subtitleView = (TextView) view .findViewById(com.saarang.samples.apps.iosched.R.id.session_subtitle); final TextView shortSubtitleView = (TextView) view .findViewById(com.saarang.samples.apps.iosched.R.id.session_subtitle_short); final TextView snippetView = (TextView) view .findViewById(com.saarang.samples.apps.iosched.R.id.session_snippet); final TextView abstractView = (TextView) view .findViewById(com.saarang.samples.apps.iosched.R.id.session_abstract); final TextView categoryView = (TextView) view .findViewById(com.saarang.samples.apps.iosched.R.id.session_category); final View sessionTargetView = view.findViewById(com.saarang.samples.apps.iosched.R.id.session_target); if (sessionColor == 0) { // use default sessionColor = mDefaultSessionColor; } if (mNoTrackBranding) { sessionColor = getResources() .getColor(com.saarang.samples.apps.iosched.R.color.no_track_branding_session_color); } darkSessionColor = UIUtils.scaleSessionColorToDefaultBG(sessionColor); ImageView photoView = (ImageView) view .findViewById(com.saarang.samples.apps.iosched.R.id.session_photo_colored); if (photoView != null) { if (!mPreloader.isDimensSet()) { final ImageView finalPhotoView = photoView; photoView.post(new Runnable() { @Override public void run() { mPreloader.setDimens(finalPhotoView.getWidth(), finalPhotoView.getHeight()); } }); } // colored photoView.setColorFilter(mNoTrackBranding ? new PorterDuffColorFilter( getResources().getColor( com.saarang.samples.apps.iosched.R.color.no_track_branding_session_tile_overlay), PorterDuff.Mode.SRC_ATOP) : UIUtils.makeSessionImageScrimColorFilter(darkSessionColor)); } else { photoView = (ImageView) view.findViewById(com.saarang.samples.apps.iosched.R.id.session_photo); } ViewCompat.setTransitionName(photoView, "photo_" + sessionId); // when we load a photo, it will fade in from transparent so the // background of the container must be the session color to avoid a white flash ViewParent parent = photoView.getParent(); if (parent != null && parent instanceof View) { ((View) parent).setBackgroundColor(darkSessionColor); } else { photoView.setBackgroundColor(darkSessionColor); } String photo = mCursor.getString(SessionsQuery.PHOTO_URL); if (!TextUtils.isEmpty(photo)) { mImageLoader.loadImage(photo, photoView, true /*crop*/); } else { // cleaning the (potentially) recycled photoView, in case this session has no photo: photoView.setImageDrawable(null); } // render title titleView.setText(sessionTitle == null ? "?" : sessionTitle); // render subtitle into either the subtitle view, or the short subtitle view, as available if (subtitleView != null) { subtitleView.setText(UIUtils.formatSessionSubtitle(sessionStart, sessionEnd, roomName, mBuffer, context) + liveNowText); } else if (shortSubtitleView != null) { shortSubtitleView.setText( UIUtils.formatSessionSubtitle(sessionStart, sessionEnd, roomName, mBuffer, context, true) + liveNowText); } // render category if (categoryView != null) { TagMetadata.Tag groupTag = mTagMetadata.getSessionGroupTag(tags); if (groupTag != null && !Config.Tags.SESSIONS.equals(groupTag.getId())) { categoryView.setText(groupTag.getName()); categoryView.setVisibility(View.VISIBLE); } else { categoryView.setVisibility(View.GONE); } } // if a snippet view is available, render the session snippet there. if (snippetView != null) { if (mIsSearchCursor) { // render the search snippet into the snippet view snippetView.setText(" "); } else { // render speaker names and abstracts into the snippet view mBuffer.setLength(0); if (!TextUtils.isEmpty(speakerNames)) { mBuffer.append(speakerNames).append(". "); } if (!TextUtils.isEmpty(sessionAbstract)) { mBuffer.append(sessionAbstract); } snippetView.setText(""); } } if (abstractView != null && !mIsSearchCursor) { // render speaker names and abstracts into the abstract view mBuffer.setLength(0); if (!TextUtils.isEmpty(speakerNames)) { mBuffer.append(speakerNames).append("\n\n"); } if (!TextUtils.isEmpty(sessionAbstract)) { mBuffer.append(sessionAbstract); } abstractView.setText(""); } // show or hide the "in my schedule" indicator view.findViewById(com.saarang.samples.apps.iosched.R.id.indicator_in_schedule) .setVisibility(starred ? View.VISIBLE : View.INVISIBLE); // if we are in condensed mode and this card is the hero card (big card at the top // of the screen), set up the message card if necessary. if (!useExpandedMode() && groupId == HERO_GROUP_ID) { // this is the hero view, so we might want to show a message card final boolean cardShown = setupMessageCard(view); // if this is the wide hero layout, show or hide the card or the session abstract // view, as appropriate (they are mutually exclusive). final View cardContainer = view .findViewById(com.saarang.samples.apps.iosched.R.id.message_card_container_wide); final View abstractContainer = view .findViewById(com.saarang.samples.apps.iosched.R.id.session_abstract); if (cardContainer != null && abstractContainer != null) { cardContainer.setVisibility(cardShown ? View.VISIBLE : View.GONE); abstractContainer.setVisibility(cardShown ? View.GONE : View.VISIBLE); abstractContainer.setBackgroundColor(darkSessionColor); } } // if this session is live right now, display the "LIVE NOW" icon on top of it View liveNowBadge = view.findViewById(com.saarang.samples.apps.iosched.R.id.live_now_badge); if (liveNowBadge != null) { liveNowBadge.setVisibility(happeningNow && hasLivestream ? View.VISIBLE : View.GONE); } // if this view is clicked, open the session details view final View finalPhotoView = photoView; sessionTargetView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { mCallbacks.onSessionSelected(sessionId, finalPhotoView); } }); // animate this card if (dataIndex > mMaxDataIndexAnimated) { mMaxDataIndexAnimated = dataIndex; } }
From source file:com.android.mail.ui.ConversationListFragment.java
/** * Used with SwipeableListView to change conv_list backgrounds to work around shadow elevation * issues causing and overdraw problems due to static backgrounds. * * @param view/* ww w. j ava2s . com*/ * @param scrollState */ @Override public void onScrollStateChanged(final AbsListView view, final int scrollState) { mListView.onScrollStateChanged(view, scrollState); final View rootView = getView(); // It seems that the list view is reading the scroll state, but the onCreateView has not // yet finished and the root view is null, so check that if (rootView != null) { // If not scrolling, assign default background - white for tablet, transparent for phone if (scrollState == AbsListView.OnScrollListener.SCROLL_STATE_IDLE) { rootView.setBackgroundColor(mDefaultListBackgroundColor); // Otherwise, list is scrolling, so remove background (corresponds to 0 input) } else { rootView.setBackgroundResource(0); } } }
From source file:com.nps.micro.view.TestsSectionFragment.java
private void createDeviceChooser(View rootView, final Button runButton) { availableDevicesListView = (ListView) rootView.findViewById(R.id.availableDevicesListView); availableDevicesAdapter = new ArrayAdapter<String>(getActivity(), R.layout.text_view, devicesList); availableDevicesListView.setAdapter(availableDevicesAdapter); availableDevicesListView.setTextFilterEnabled(true); availableDevicesListView.setOnItemClickListener(new OnItemClickListener() { @Override//from w w w.j a v a 2s .c o m public void onItemClick(AdapterView<?> parent, final View view, int position, long id) { String item = (String) parent.getItemAtPosition(position); selectedDevices.add(ensureUniqueItem(item)); selectedDevicesAdapter = new StableArrayAdapter(getActivity(), R.layout.text_view, selectedDevices); selectedDevicesListView.setAdapter(selectedDevicesAdapter); setListViewHeightBasedOnChildren(selectedDevicesListView); updateModelSelectedDevices(); } private String ensureUniqueItem(String item) { if (selectedDevices.contains(item)) { return ensureUniqueItem(item + "'"); } else { return item; } } }); availableDevicesListView.setOnItemLongClickListener(new OnItemLongClickListener() { @Override public boolean onItemLongClick(AdapterView<?> parent, final View view, int position, long id) { view.setBackgroundColor(Color.CYAN); final String item = (String) parent.getItemAtPosition(position); final String msg = getResources().getString(R.string.ping_device_info); AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); builder.setTitle(R.string.ping_device_title).setMessage(String.format(msg, item)) .setPositiveButton(R.string.ping, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { view.setBackgroundColor(Color.BLACK); if (listener != null) { listener.pingDevice(item); } dialog.dismiss(); } }).setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { view.setBackgroundColor(Color.BLACK); dialog.dismiss(); } }); builder.create().show(); return true; } }); setListViewHeightBasedOnChildren(availableDevicesListView); selectedDevicesListView = (DynamicListView) rootView.findViewById(R.id.selectedDevicesListView); selectedDevicesListView.setChoiceMode(ListView.CHOICE_MODE_SINGLE); selectedDevicesAdapter = new StableArrayAdapter(getActivity(), R.layout.text_view, selectedDevices); selectedDevicesListView.setListItems(selectedDevices); selectedDevicesListView.setAdapter(selectedDevicesAdapter); selectedDevicesListView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> parent, final View view, int position, long id) { final String item = (String) parent.getItemAtPosition(position); selectedDevices.remove(item); selectedDevicesAdapter = new StableArrayAdapter(getActivity(), R.layout.text_view, selectedDevices); selectedDevicesListView.setAdapter(selectedDevicesAdapter); setListViewHeightBasedOnChildren(selectedDevicesListView); updateModelSelectedDevices(); } }); selectedDevicesListView.setOnTouchListener(new ListView.OnTouchListener() { @Override public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); switch (action) { case MotionEvent.ACTION_DOWN: v.getParent().requestDisallowInterceptTouchEvent(true); break; case MotionEvent.ACTION_UP: v.getParent().requestDisallowInterceptTouchEvent(false); break; } v.onTouchEvent(event); return true; } }); setListViewHeightBasedOnChildren(selectedDevicesListView); }
From source file:cs.umass.edu.prepare.view.custom.CalendarAdapter.java
public View getView(int position, View convertView, ViewGroup parent) { View v = convertView; TextView dayView;/* www .j a va 2 s. c o m*/ if (convertView == null) { // if it's not recycled, initialize some attributes v = View.inflate(context, R.layout.calendar_item, null); } ViewGroup insertPoint = (ViewGroup) v.findViewById(R.id.layout_calendar_item); insertPoint.removeAllViews(); dayView = (TextView) View.inflate(context, R.layout.textview_date, null); insertPoint.addView(dayView); // disable empty days from the beginning if (dateStrings[position].equals("")) { dayView.setClickable(false); dayView.setFocusable(false); } else { v.setBackgroundResource(R.drawable.list_item_background); Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, month.get(Calendar.YEAR)); cal.set(Calendar.MONTH, month.get(Calendar.MONTH)); cal.set(Calendar.DAY_OF_MONTH, Integer.parseInt(dateStrings[position])); int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK); if (month.get(Calendar.YEAR) == selectedDate.get(Calendar.YEAR) && month.get(Calendar.MONTH) == selectedDate.get(Calendar.MONTH) && dateStrings[position].equals("" + selectedDate.get(Calendar.DAY_OF_MONTH))) { int selectedColor = ContextCompat.getColor(context, R.color.color_calendar_item_background_selected); v.setBackgroundColor(selectedColor); } else if (dayOfWeek == Calendar.SATURDAY || dayOfWeek == Calendar.SUNDAY) { dayView.setTextColor(Color.GRAY); } } dayView.setText(dateStrings[position]); // create date string for comparison String dateStr = dateStrings[position]; if (displayType == DisplayType.BASIC) { v.setMinimumHeight(0); return v; // do not populate cells } v.setMinimumHeight(325); // TODO: not device independent if (medications == null || adherenceData == null) { Log.w(TAG, "Warning : No adherenceData found."); return v; // do not populate cells } if (dateStr.equals("")) return v; Calendar dateKey = Utils.getDateKey(month.get(Calendar.YEAR), month.get(Calendar.MONTH), Integer.parseInt(dateStr)); if (adherenceData.containsKey(dateKey)) { populateCell(dateKey, insertPoint); } return v; }
From source file:androidx.media.widget.VideoView2.java
private void inflateMusicView(int layoutId) { removeView(mMusicView);/*from w w w . ja va2 s.co m*/ LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); View v = inflater.inflate(layoutId, null); v.setBackgroundColor(mDominantColor); ImageView albumView = v.findViewById(R.id.album); if (albumView != null) { albumView.setImageDrawable(mMusicAlbumDrawable); } TextView titleView = v.findViewById(R.id.title); if (titleView != null) { titleView.setText(mMusicTitleText); } TextView artistView = v.findViewById(R.id.artist); if (artistView != null) { artistView.setText(mMusicArtistText); } mMusicView = v; addView(mMusicView, 0); }
From source file:org.liberty.android.fantastischmemo.ui.QACardActivity.java
protected void displayCard(boolean showAnswer) { // First prepare the text to display String questionTypeface = setting.getQuestionFont(); String answerTypeface = setting.getAnswerFont(); Setting.Align questionAlign = setting.getQuestionTextAlign(); Setting.Align answerAlign = setting.getAnswerTextAlign(); String questionTypefaceValue = null; String answerTypefaceValue = null; /* Set the typeface of question and answer */ if (!Strings.isNullOrEmpty(questionTypeface)) { questionTypefaceValue = questionTypeface; }// ww w . j av a 2 s.co m if (!Strings.isNullOrEmpty(answerTypeface)) { answerTypefaceValue = answerTypeface; } final String[] imageSearchPaths = { /* Relative path */ "", /* Relative path with db name */ "" + FilenameUtils.getName(dbPath), /* Try the image in /sdcard/anymemo/images/dbname/ */ AMEnv.DEFAULT_IMAGE_PATH + FilenameUtils.getName(dbPath), /* Try the image in /sdcard/anymemo/images/ */ AMEnv.DEFAULT_IMAGE_PATH, }; // Buttons view can be null if it is not decleared in the layout XML View buttonsView = findViewById(R.id.buttons_root); if (buttonsView != null) { // Make sure the buttons view are also handling the event for the answer view // e. g. clicking on the blank area of the buttons layout to reveal the answer // or flip the card. buttonsView.setOnClickListener(new View.OnClickListener() { public void onClick(View v) { onQuestionViewClickListener.onClick(v); } }); // Also the buttons should match the color of the view above. // It could be the question if it is the double sided card with only question shown // or answer view's color. if (!setting.isDefaultColor()) { if (setting.getCardStyle() == Setting.CardStyle.DOUBLE_SIDED && !showAnswer) { buttonsView.setBackgroundColor(setting.getQuestionBackgroundColor()); } else { buttonsView.setBackgroundColor(setting.getAnswerBackgroundColor()); } } } CardFragment.Builder questionFragmentBuilder = new CardFragment.Builder(getCurrentCard().getQuestion()) .setTextAlignment(questionAlign).setTypefaceFromFile(questionTypefaceValue) .setTextOnClickListener(onQuestionTextClickListener) .setCardOnClickListener(onQuestionViewClickListener).setTextFontSize(setting.getQuestionFontSize()) .setTypefaceFromFile(setting.getQuestionFont()) .setDisplayInHtml(setting.getDisplayInHTMLEnum().contains(Setting.CardField.QUESTION)) .setHtmlLinebreakConversion(setting.getHtmlLineBreakConversion()) .setImageSearchPaths(imageSearchPaths); CardFragment.Builder answerFragmentBuilder = new CardFragment.Builder(getCurrentCard().getAnswer()) .setTextAlignment(answerAlign).setTypefaceFromFile(answerTypefaceValue) .setTextOnClickListener(onAnswerTextClickListener).setCardOnClickListener(onAnswerViewClickListener) .setTextFontSize(setting.getAnswerFontSize()).setTypefaceFromFile(setting.getAnswerFont()) .setDisplayInHtml(setting.getDisplayInHTMLEnum().contains(Setting.CardField.ANSWER)) .setHtmlLinebreakConversion(setting.getHtmlLineBreakConversion()) .setImageSearchPaths(imageSearchPaths); CardFragment.Builder showAnswerFragmentBuilder = new CardFragment.Builder( "?\n" + getString(R.string.memo_show_answer)).setTextAlignment(Setting.Align.CENTER) .setTypefaceFromFile(answerTypefaceValue).setTextOnClickListener(onAnswerTextClickListener) .setCardOnClickListener(onAnswerViewClickListener) .setTextFontSize(setting.getAnswerFontSize()).setTypefaceFromFile(setting.getAnswerFont()); // For default card colors, we will use the theme's color // so we do not set the colors here. if (!setting.isDefaultColor()) { questionFragmentBuilder.setTextColor(setting.getQuestionTextColor()) .setBackgroundColor(setting.getQuestionBackgroundColor()); answerFragmentBuilder.setTextColor(setting.getAnswerTextColor()) .setBackgroundColor(setting.getAnswerBackgroundColor()); showAnswerFragmentBuilder.setTextColor(setting.getAnswerTextColor()) .setBackgroundColor(setting.getAnswerBackgroundColor()); } // Note is currently shared some settings with Answer CardFragment.Builder noteFragmentBuilder = new CardFragment.Builder(getCurrentCard().getNote()) .setTextAlignment(answerAlign).setTypefaceFromFile(answerTypefaceValue) .setCardOnClickListener(onAnswerViewClickListener).setTextFontSize(setting.getAnswerFontSize()) .setTypefaceFromFile(setting.getAnswerFont()) .setDisplayInHtml(setting.getDisplayInHTMLEnum().contains(Setting.CardField.ANSWER)) .setHtmlLinebreakConversion(setting.getHtmlLineBreakConversion()) .setImageSearchPaths(imageSearchPaths); // Long click to launch image viewer if the card has an image questionFragmentBuilder.setTextOnLongClickListener( generateImageOnLongClickListener(getCurrentCard().getQuestion(), imageSearchPaths)); answerFragmentBuilder.setTextOnLongClickListener( generateImageOnLongClickListener(getCurrentCard().getAnswer(), imageSearchPaths)); FragmentTransaction ft = getSupportFragmentManager().beginTransaction(); if (setting.getCardStyle() == Setting.CardStyle.SINGLE_SIDED) { TwoFieldsCardFragment fragment = new TwoFieldsCardFragment(); Bundle b = new Bundle(); // Handle card field setting. List<CardFragment.Builder> builders1List = new ArrayList<CardFragment.Builder>(4); if (setting.getQuestionFieldEnum().contains(Setting.CardField.QUESTION)) { builders1List.add(questionFragmentBuilder); } if (setting.getQuestionFieldEnum().contains(Setting.CardField.ANSWER)) { builders1List.add(answerFragmentBuilder); } if (setting.getQuestionFieldEnum().contains(Setting.CardField.NOTE)) { builders1List.add(noteFragmentBuilder); } List<CardFragment.Builder> builders2List = new ArrayList<CardFragment.Builder>(4); if (!showAnswer) { builders2List.add(showAnswerFragmentBuilder); } if (setting.getAnswerFieldEnum().contains(Setting.CardField.QUESTION)) { builders2List.add(questionFragmentBuilder); } if (setting.getAnswerFieldEnum().contains(Setting.CardField.ANSWER)) { builders2List.add(answerFragmentBuilder); } if (setting.getAnswerFieldEnum().contains(Setting.CardField.NOTE)) { builders2List.add(noteFragmentBuilder); } CardFragment.Builder[] builders1 = new CardFragment.Builder[builders1List.size()]; builders1List.toArray(builders1); CardFragment.Builder[] builders2 = new CardFragment.Builder[builders2List.size()]; builders2List.toArray(builders2); b.putSerializable(TwoFieldsCardFragment.EXTRA_FIELD1_CARD_FRAGMENT_BUILDERS, builders1); b.putSerializable(TwoFieldsCardFragment.EXTRA_FIELD2_CARD_FRAGMENT_BUILDERS, builders2); if (showAnswer) { b.putInt(TwoFieldsCardFragment.EXTRA_FIELD2_INITIAL_POSITION, 0); } else { b.putInt(TwoFieldsCardFragment.EXTRA_FIELD2_INITIAL_POSITION, 0); } b.putInt(TwoFieldsCardFragment.EXTRA_QA_RATIO, setting.getQaRatio()); b.putInt(TwoFieldsCardFragment.EXTRA_SEPARATOR_COLOR, setting.getSeparatorColor()); fragment.setArguments(b); configCardFragmentTransitionAnimation(ft); ft.replace(R.id.card_root, fragment); ft.commit(); } else if (setting.getCardStyle() == Setting.CardStyle.DOUBLE_SIDED) { FlipableCardFragment fragment = new FlipableCardFragment(); Bundle b = new Bundle(1); CardFragment.Builder[] builders = { questionFragmentBuilder, answerFragmentBuilder, noteFragmentBuilder }; b.putSerializable(FlipableCardFragment.EXTRA_CARD_FRAGMENT_BUILDERS, builders); if (showAnswer) { b.putInt(FlipableCardFragment.EXTRA_INITIAL_POSITION, 1); } else { b.putInt(FlipableCardFragment.EXTRA_INITIAL_POSITION, 0); } fragment.setArguments(b); configCardFragmentTransitionAnimation(ft); ft.replace(R.id.card_root, fragment); ft.commit(); } else { assert false : "Card logic not implemented for style: " + setting.getCardStyle(); } isAnswerShown = showAnswer; // Set up the small title bar // It is defualt "GONE" so it won't take any space // if there is no text smallTitleBar = (TextView) findViewById(R.id.small_title_bar); // Only copy to clipboard if answer is show // as a feature request: // http://code.google.com/p/anymemo/issues/detail?id=239 if (showAnswer == true) { copyToClipboard(); } currentDisplayedCard = getCurrentCard(); onPostDisplayCard(); }
From source file:com.serenegiant.aceparrot.BaseFragment.java
/** * ??ImageView??????/*from w ww . j av a 2 s .c om*/ * reset_delay?0?????????? * @param view * @param color * @param reset_delay */ protected void setColorFilter(final View view, final int color, final long reset_delay) { if (view instanceof ImageView) { runOnUiThread(new Runnable() { @Override public void run() { ((ImageView) view).setColorFilter(color); } }); if (reset_delay > 0) { ResetColorFilterTask task = mResetColorFilterTasks.get(view); if (task == null) { task = new ResetColorFilterTask(((ImageView) view)); mResetColorFilterTasks.put(view, task); } removeFromUIThread(task); runOnUiThread(task, reset_delay); // UI?? } } else { runOnUiThread(new Runnable() { @Override public void run() { view.setBackgroundColor(color); } }); if (reset_delay > 0) { ResetColorFilterTask task = mResetColorFilterTasks.get(view); if (task == null) { task = new ResetColorFilterTask(view); } removeFromUIThread(task); runOnUiThread(task, reset_delay); // UI?? } } }
From source file:com.silentcircle.accounts.AccountStep3.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { super.onCreate(savedInstanceState); View stepView = inflater.inflate(R.layout.provisioning_bp_s3, container, false); if (stepView == null) return null; mTcCheckbox = (CheckBox) stepView.findViewById(R.id.CheckBoxTC); mProgress = (ProgressBar) stepView.findViewById(R.id.ProgressBar); mProgressInner = stepView.findViewById(R.id.ProvisioningInProgress); mScroll = (ScrollView) stepView.findViewById(R.id.Scroll); mButtons = (LinearLayout) stepView.findViewById(R.id.ProvisioningButtons); mAuthToken = (TextView) stepView.findViewById(R.id.ProvisioningAuthTokenInput); mAuthToken.setHint(getString(R.string.provisioning_auth_token_hint)); ((TextView) stepView.findViewById(R.id.CheckBoxTCText)).setMovementMethod(LinkMovementMethod.getInstance()); stepView.findViewById(R.id.back).setOnClickListener(this); stepView.findViewById(R.id.create).setOnClickListener(this); TextView headerText = (TextView) stepView.findViewById(R.id.HeaderText); stepView.setBackgroundColor(ContextCompat.getColor(mParent, R.color.auth_background_grey)); if (mUseExistingAccount) { headerText.setText(getString(R.string.sign_in)); ((TextView) stepView.findViewById(R.id.create)).setText(getText(R.string.next)); startLoadingRegisterDevice();/* w w w . ja va2s . com*/ } else { startLoadingCreateAccount(); } mAuthToken.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { } @Override public void afterTextChanged(Editable s) { // Only enable the button if the token is 6 digits long. View mButton = mButtons.findViewById(R.id.create); Boolean bEnable = s.toString().length() == 6; mButton.setEnabled(bEnable); if (bEnable) mButton.setAlpha((float) 1); else mButton.setAlpha((float) 0.5); } }); return stepView; }
From source file:com.aware.Aware.java
/** * Given a plugin's package name, fetch the context card for reuse. * @param context: application context// ww w . ja v a2s .c o m * @param package_name: plugin's package name * @return View for reuse (instance of LinearLayout) */ public static View getContextCard(final Context context, final String package_name) { if (!isClassAvailable(context, package_name, "ContextCard")) { return null; } String ui_class = package_name + ".ContextCard"; LinearLayout card = new LinearLayout(context); LayoutParams params = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); card.setLayoutParams(params); card.setOrientation(LinearLayout.VERTICAL); try { Context packageContext = context.createPackageContext(package_name, Context.CONTEXT_INCLUDE_CODE | Context.CONTEXT_IGNORE_SECURITY); Class<?> fragment_loader = packageContext.getClassLoader().loadClass(ui_class); Object fragment = fragment_loader.newInstance(); Method[] allMethods = fragment_loader.getDeclaredMethods(); Method m = null; for (Method mItem : allMethods) { String mName = mItem.getName(); if (mName.contains("getContextCard")) { mItem.setAccessible(true); m = mItem; break; } } View ui = (View) m.invoke(fragment, packageContext); if (ui != null) { //Check if plugin has settings. If it does, tapping the card shows the settings if (isClassAvailable(context, package_name, "Settings")) { ui.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent open_settings = new Intent(); open_settings.setClassName(package_name, package_name + ".Settings"); open_settings.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(open_settings); } }); } //Set card look-n-feel ui.setBackgroundColor(Color.WHITE); ui.setPadding(20, 20, 20, 20); card.addView(ui); LinearLayout shadow = new LinearLayout(context); LayoutParams params_shadow = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT); params_shadow.setMargins(0, 0, 0, 10); shadow.setBackgroundColor(context.getResources().getColor(R.color.card_shadow)); shadow.setMinimumHeight(5); shadow.setLayoutParams(params_shadow); card.addView(shadow); return card; } else { return null; } } catch (NameNotFoundException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NullPointerException e) { e.printStackTrace(); } catch (InstantiationException e) { e.printStackTrace(); } return null; }
From source file:com.android.app.MediaPlaybackActivity.java
public boolean onTouch(View v, MotionEvent event) { int action = event.getAction(); TextView tv = textViewForContainer(v); if (tv == null) { return false; }//from ww w .j a v a 2 s . c om if (action == MotionEvent.ACTION_DOWN) { v.setBackgroundColor(0xff606060); mInitialX = mLastX = (int) event.getX(); mDraggingLabel = false; } else if (action == MotionEvent.ACTION_UP || action == MotionEvent.ACTION_CANCEL) { v.setBackgroundColor(0); if (mDraggingLabel) { Message msg = mLabelScroller.obtainMessage(0, tv); mLabelScroller.sendMessageDelayed(msg, 1000); } } else if (action == MotionEvent.ACTION_MOVE) { if (mDraggingLabel) { int scrollx = tv.getScrollX(); int x = (int) event.getX(); int delta = mLastX - x; if (delta != 0) { mLastX = x; scrollx += delta; if (scrollx > mTextWidth) { // scrolled the text completely off the view to the left scrollx -= mTextWidth; scrollx -= mViewWidth; } if (scrollx < -mViewWidth) { // scrolled the text completely off the view to the right scrollx += mViewWidth; scrollx += mTextWidth; } tv.scrollTo(scrollx, 0); } return true; } int delta = mInitialX - (int) event.getX(); if (Math.abs(delta) > mTouchSlop) { // start moving mLabelScroller.removeMessages(0, tv); // Only turn ellipsizing off when it's not already off, because it // causes the scroll position to be reset to 0. if (tv.getEllipsize() != null) { tv.setEllipsize(null); } Layout ll = tv.getLayout(); // layout might be null if the text just changed, or ellipsizing // was just turned off if (ll == null) { return false; } // get the non-ellipsized line width, to determine whether scrolling // should even be allowed mTextWidth = (int) tv.getLayout().getLineWidth(0); mViewWidth = tv.getWidth(); if (mViewWidth > mTextWidth) { tv.setEllipsize(TruncateAt.END); v.cancelLongPress(); return false; } mDraggingLabel = true; tv.setHorizontalFadingEdgeEnabled(true); v.cancelLongPress(); return true; } } return false; }