List of usage examples for android.widget TextView setVisibility
@RemotableViewMethod public void setVisibility(@Visibility int visibility)
From source file:com.google.android.apps.iosched.ui.SessionDetailFragment.java
private void onSpeakersQueryComplete(Cursor cursor) { try {/*from w w w .jav a2s . c o m*/ mSpeakersCursor = true; // TODO: remove any existing speakers from layout, since this cursor // might be from a data change notification. final ViewGroup speakersGroup = (ViewGroup) mRootView.findViewById(R.id.session_speakers_block); final LayoutInflater inflater = getActivity().getLayoutInflater(); boolean hasSpeakers = false; while (cursor.moveToNext()) { final String speakerName = cursor.getString(SpeakersQuery.SPEAKER_NAME); if (TextUtils.isEmpty(speakerName)) { continue; } final String speakerImageUrl = cursor.getString(SpeakersQuery.SPEAKER_IMAGE_URL); final String speakerCompany = cursor.getString(SpeakersQuery.SPEAKER_COMPANY); final String speakerUrl = cursor.getString(SpeakersQuery.SPEAKER_URL); final String speakerAbstract = cursor.getString(SpeakersQuery.SPEAKER_ABSTRACT); String speakerHeader = speakerName; if (!TextUtils.isEmpty(speakerCompany)) { speakerHeader += ", " + speakerCompany; } final View speakerView = inflater.inflate(R.layout.speaker_detail, speakersGroup, false); final TextView speakerHeaderView = (TextView) speakerView.findViewById(R.id.speaker_header); final ImageView speakerImgView = (ImageView) speakerView.findViewById(R.id.speaker_image); final TextView speakerUrlView = (TextView) speakerView.findViewById(R.id.speaker_url); final TextView speakerAbstractView = (TextView) speakerView.findViewById(R.id.speaker_abstract); if (!TextUtils.isEmpty(speakerImageUrl)) { BitmapUtils.fetchImage(getActivity(), speakerImageUrl, null, null, new BitmapUtils.OnFetchCompleteListener() { public void onFetchComplete(Object cookie, Bitmap result) { if (result != null) { speakerImgView.setImageBitmap(result); } } }); } speakerHeaderView.setText(speakerHeader); UIUtils.setTextMaybeHtml(speakerAbstractView, speakerAbstract); if (!TextUtils.isEmpty(speakerUrl)) { UIUtils.setTextMaybeHtml(speakerUrlView, speakerUrl); speakerUrlView.setVisibility(View.VISIBLE); } else { speakerUrlView.setVisibility(View.GONE); } speakersGroup.addView(speakerView); hasSpeakers = true; mHasSummaryContent = true; } speakersGroup.setVisibility(hasSpeakers ? View.VISIBLE : View.GONE); // Show empty message when all data is loaded, and nothing to show if (mSessionCursor && !mHasSummaryContent) { mRootView.findViewById(android.R.id.empty).setVisibility(View.VISIBLE); } } finally { if (null != cursor) { cursor.close(); } } }
From source file:com.krayzk9s.imgurholo.ui.SingleImageFragment.java
@Override public boolean onOptionsItemSelected(MenuItem item) { // handle item selection final Activity activity = getActivity(); switch (item.getItemId()) { case R.id.action_sort: return true; case R.id.menuSortNewest: sort = "New"; refreshComments();/*from w w w . ja v a2s .c o m*/ activity.invalidateOptionsMenu(); return true; case R.id.menuSortTop: sort = "Top"; refreshComments(); activity.invalidateOptionsMenu(); return true; case R.id.menuSortBest: sort = "Best"; refreshComments(); activity.invalidateOptionsMenu(); return true; case R.id.action_refresh: refreshComments(); return true; case R.id.action_submit: final EditText newGalleryTitle = new EditText(activity); newGalleryTitle.setHint("Title"); newGalleryTitle.setSingleLine(); new AlertDialog.Builder(activity).setTitle("Set Gallery Title/Press OK to remove") .setView(newGalleryTitle) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { if (newGalleryTitle.getText() == null) return; HashMap<String, Object> galleryMap = new HashMap<String, Object>(); galleryMap.put("terms", "1"); galleryMap.put(ImgurHoloActivity.IMAGE_DATA_TITLE, newGalleryTitle.getText().toString()); newGalleryString = newGalleryTitle.getText().toString(); try { Fetcher fetcher = new Fetcher(singleImageFragment, "3/gallery/image/" + imageData.getJSONObject().getString("id"), ApiCall.GET, galleryMap, ((ImgurHoloActivity) getActivity()).getApiCall(), GALLERY); fetcher.execute(); } catch (Exception 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(); return true; case R.id.action_edit: try { final EditText newTitle = new EditText(activity); newTitle.setSingleLine(); if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE).equals("null")) newTitle.setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_TITLE)); final EditText newBody = new EditText(activity); newBody.setHint(R.string.body_hint_description); newTitle.setHint(R.string.body_hint_title); if (!imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION).equals("null")) newBody.setText(imageData.getJSONObject().getString(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION)); LinearLayout linearLayout = new LinearLayout(activity); linearLayout.setOrientation(LinearLayout.VERTICAL); linearLayout.addView(newTitle); linearLayout.addView(newBody); new AlertDialog.Builder(activity).setTitle(R.string.dialog_edit_title).setView(linearLayout) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { TextView imageTitle = (TextView) imageLayoutView .findViewById(R.id.single_image_title); TextView imageDescription = (TextView) imageLayoutView .findViewById(R.id.single_image_description); if (newTitle.getText() != null && !newTitle.getText().toString().equals("")) { imageTitle.setText(newTitle.getText().toString()); imageTitle.setVisibility(View.VISIBLE); } else imageTitle.setVisibility(View.GONE); if (newBody.getText() != null && !newBody.getText().toString().equals("")) { imageDescription.setText(newBody.getText().toString()); imageDescription.setVisibility(View.VISIBLE); } else imageDescription.setVisibility(View.GONE); HashMap<String, Object> editImageMap = new HashMap<String, Object>(); editImageMap.put(ImgurHoloActivity.IMAGE_DATA_TITLE, newTitle.getText().toString()); editImageMap.put(ImgurHoloActivity.IMAGE_DATA_DESCRIPTION, newBody.getText().toString()); try { Fetcher fetcher = new Fetcher(singleImageFragment, "3/image/" + imageData.getJSONObject().getString("id"), ApiCall.POST, editImageMap, ((ImgurHoloActivity) getActivity()).getApiCall(), EDITIMAGE); 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(); } catch (JSONException e) { Log.e("Error!", "oops, some image fields missing values" + e.toString()); } return true; case R.id.action_download: ImageUtils.downloadImage(this, imageData); return true; case R.id.action_delete: new AlertDialog.Builder(activity).setTitle(R.string.dialog_delete_confirmation_title) .setMessage(R.string.dialog_delete_confirmation_summary) .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { try { Fetcher fetcher = new Fetcher(singleImageFragment, "3/image/" + imageData.getJSONObject().getString("id"), ApiCall.DELETE, null, ((ImgurHoloActivity) getActivity()).getApiCall(), DELETE); fetcher.execute(); } catch (JSONException e) { Log.e("Error!", e.toString()); } } }).setNegativeButton("Cancel", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int whichButton) { // Do nothing. } }).show(); return true; case R.id.action_copy: ImageUtils.copyImageURL(this, imageData); return true; case R.id.action_share: ImageUtils.shareImage(this, imageData); return true; default: return super.onOptionsItemSelected(item); } }
From source file:de.geeksfactory.opacclient.frontend.AccountFragment.java
private void setTextOrHide(String value, TextView tv) { if (!TextUtils.isEmpty(value)) { tv.setText(value);//from w w w . j a va 2s .c o m } else { tv.setVisibility(View.GONE); } }
From source file:cgeo.geocaching.CacheDetailActivity.java
private static void setPersonalNote(final TextView personalNoteView, final String personalNote) { personalNoteView.setText(personalNote, TextView.BufferType.SPANNABLE); if (StringUtils.isNotBlank(personalNote)) { personalNoteView.setVisibility(View.VISIBLE); Linkify.addLinks(personalNoteView, Linkify.MAP_ADDRESSES | Linkify.WEB_URLS); } else {// www .jav a 2 s.c om personalNoteView.setVisibility(View.GONE); } }
From source file:com.borax12.materialdaterangepicker.single.time.TimePickerDialog.java
@Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.inflate(R.layout.mdtp_time_picker_dialog_single, container, false); KeyboardListener keyboardListener = new KeyboardListener(); view.findViewById(R.id.time_picker_dialog).setOnKeyListener(keyboardListener); // If an accent color has not been set manually, get it from the context if (mAccentColor == -1) { mAccentColor = Utils.getAccentColorFromThemeIfAvailable(getActivity()); }// ww w . ja va2 s. c om // if theme mode has not been set by java code, check if it is specified in Style.xml if (!mThemeDarkChanged) { mThemeDark = Utils.isDarkTheme(getActivity(), mThemeDark); } Resources res = getResources(); Context context = getActivity(); mHourPickerDescription = res.getString(R.string.mdtp_hour_picker_description); mSelectHours = res.getString(R.string.mdtp_select_hours); mMinutePickerDescription = res.getString(R.string.mdtp_minute_picker_description); mSelectMinutes = res.getString(R.string.mdtp_select_minutes); mSecondPickerDescription = res.getString(R.string.mdtp_second_picker_description); mSelectSeconds = res.getString(R.string.mdtp_select_seconds); mSelectedColor = ContextCompat.getColor(context, R.color.mdtp_white); mUnselectedColor = ContextCompat.getColor(context, R.color.mdtp_accent_color_focused); mHourView = (TextView) view.findViewById(R.id.hours); mHourView.setOnKeyListener(keyboardListener); mHourSpaceView = (TextView) view.findViewById(R.id.hour_space); mMinuteSpaceView = (TextView) view.findViewById(R.id.minutes_space); mMinuteView = (TextView) view.findViewById(R.id.minutes); mMinuteView.setOnKeyListener(keyboardListener); mSecondSpaceView = (TextView) view.findViewById(R.id.seconds_space); mSecondView = (TextView) view.findViewById(R.id.seconds); mSecondView.setOnKeyListener(keyboardListener); mAmPmTextView = (TextView) view.findViewById(R.id.ampm_label); mAmPmTextView.setOnKeyListener(keyboardListener); String[] amPmTexts = new DateFormatSymbols().getAmPmStrings(); mAmText = amPmTexts[0]; mPmText = amPmTexts[1]; mHapticFeedbackController = new HapticFeedbackController(getActivity()); mInitialTime = roundToNearest(mInitialTime); mTimePicker = (RadialPickerLayout) view.findViewById(R.id.time_picker); mTimePicker.setOnValueSelectedListener(this); mTimePicker.setOnKeyListener(keyboardListener); mTimePicker.initialize(getActivity(), this, mInitialTime, mIs24HourMode); int currentItemShowing = HOUR_INDEX; if (savedInstanceState != null && savedInstanceState.containsKey(KEY_CURRENT_ITEM_SHOWING)) { currentItemShowing = savedInstanceState.getInt(KEY_CURRENT_ITEM_SHOWING); } setCurrentItemShowing(currentItemShowing, false, true, true); mTimePicker.invalidate(); mHourView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setCurrentItemShowing(HOUR_INDEX, true, false, true); tryVibrate(); } }); mMinuteView.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { setCurrentItemShowing(MINUTE_INDEX, true, false, true); tryVibrate(); } }); mSecondView.setOnClickListener(new OnClickListener() { @Override public void onClick(View view) { setCurrentItemShowing(SECOND_INDEX, true, false, true); tryVibrate(); } }); mOkButton = (Button) view.findViewById(R.id.ok); mOkButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if (mInKbMode && isTypedTimeFullyLegal()) { finishKbMode(false); } else { tryVibrate(); } notifyOnDateListener(); dismiss(); } }); mOkButton.setOnKeyListener(keyboardListener); mOkButton.setTypeface(TypefaceHelper.get(context, "Roboto-Medium")); if (mOkString != null) mOkButton.setText(mOkString); else mOkButton.setText(mOkResid); mCancelButton = (Button) view.findViewById(R.id.cancel); mCancelButton.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { tryVibrate(); if (getDialog() != null) getDialog().cancel(); } }); mCancelButton.setTypeface(TypefaceHelper.get(context, "Roboto-Medium")); if (mCancelString != null) mCancelButton.setText(mCancelString); else mCancelButton.setText(mCancelResid); mCancelButton.setVisibility(isCancelable() ? View.VISIBLE : View.GONE); // Enable or disable the AM/PM view. mAmPmHitspace = view.findViewById(R.id.ampm_hitspace); if (mIs24HourMode) { mAmPmTextView.setVisibility(View.GONE); } else { mAmPmTextView.setVisibility(View.VISIBLE); updateAmPmDisplay(mInitialTime.isAM() ? AM : PM); mAmPmHitspace.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // Don't do anything if either AM or PM are disabled if (isAmDisabled() || isPmDisabled()) return; tryVibrate(); int amOrPm = mTimePicker.getIsCurrentlyAmOrPm(); if (amOrPm == AM) { amOrPm = PM; } else if (amOrPm == PM) { amOrPm = AM; } mTimePicker.setAmOrPm(amOrPm); } }); } // Disable seconds picker if (!mEnableSeconds) { mSecondSpaceView.setVisibility(View.GONE); view.findViewById(R.id.separator_seconds).setVisibility(View.GONE); } // Center stuff depending on what's visible if (mIs24HourMode && !mEnableSeconds) { // center first separator RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); paramsSeparator.addRule(RelativeLayout.CENTER_IN_PARENT); TextView separatorView = (TextView) view.findViewById(R.id.separator); separatorView.setLayoutParams(paramsSeparator); } else if (mEnableSeconds) { // link separator to minutes final View separator = view.findViewById(R.id.separator); RelativeLayout.LayoutParams paramsSeparator = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); paramsSeparator.addRule(RelativeLayout.LEFT_OF, R.id.minutes_space); paramsSeparator.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE); separator.setLayoutParams(paramsSeparator); if (!mIs24HourMode) { // center minutes RelativeLayout.LayoutParams paramsMinutes = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); paramsMinutes.addRule(RelativeLayout.CENTER_IN_PARENT); mMinuteSpaceView.setLayoutParams(paramsMinutes); } else { // move minutes to right of center RelativeLayout.LayoutParams paramsMinutes = new RelativeLayout.LayoutParams( LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); paramsMinutes.addRule(RelativeLayout.RIGHT_OF, R.id.center_view); mMinuteSpaceView.setLayoutParams(paramsMinutes); } } mAllowAutoAdvance = true; setHour(mInitialTime.getHour(), true); setMinute(mInitialTime.getMinute()); setSecond(mInitialTime.getSecond()); // Set up for keyboard mode. mDoublePlaceholderText = res.getString(R.string.mdtp_time_placeholder); mDeletedKeyFormat = res.getString(R.string.mdtp_deleted_key); mPlaceholderText = mDoublePlaceholderText.charAt(0); mAmKeyCode = mPmKeyCode = -1; generateLegalTimesTree(); if (mInKbMode) { mTypedTimes = savedInstanceState.getIntegerArrayList(KEY_TYPED_TIMES); tryStartingKbMode(-1); mHourView.invalidate(); } else if (mTypedTimes == null) { mTypedTimes = new ArrayList<>(); } // Set the title (if any) TextView timePickerHeader = (TextView) view.findViewById(R.id.time_picker_header); if (!mTitle.isEmpty()) { timePickerHeader.setVisibility(TextView.VISIBLE); timePickerHeader.setText(mTitle); } // Set the theme at the end so that the initialize()s above don't counteract the theme. mOkButton.setTextColor(mAccentColor); mCancelButton.setTextColor(mAccentColor); timePickerHeader.setBackgroundColor(Utils.darkenColor(mAccentColor)); view.findViewById(R.id.time_display_background).setBackgroundColor(mAccentColor); view.findViewById(R.id.time_display).setBackgroundColor(mAccentColor); if (getDialog() == null) { view.findViewById(R.id.done_background).setVisibility(View.GONE); } int circleBackground = ContextCompat.getColor(context, R.color.mdtp_circle_background); int backgroundColor = ContextCompat.getColor(context, R.color.mdtp_background_color); int darkBackgroundColor = ContextCompat.getColor(context, R.color.mdtp_light_gray); int lightGray = ContextCompat.getColor(context, R.color.mdtp_light_gray); mTimePicker.setBackgroundColor(mThemeDark ? lightGray : circleBackground); view.findViewById(R.id.time_picker_dialog) .setBackgroundColor(mThemeDark ? darkBackgroundColor : backgroundColor); return view; }
From source file:de.geeksfactory.opacclient.frontend.AccountFragment.java
private void setHtmlTextOrHide(String value, TextView tv) { if (!TextUtils.isEmpty(value)) { tv.setText(Html.fromHtml(value)); } else {//from w w w . j a v a2 s . c o m tv.setVisibility(View.GONE); } }
From source file:github.popeen.dsub.activity.SubsonicActivity.java
private void checkIfServerOutdated() { final Context context = this; if (!Util.isOffline(context)) { new Thread(new Runnable() { public void run() { SharedPreferences prefs = Util.getPreferences(context); String url = Util.getRestUrl(context, "ping") + "&f=json"; final String input = KakaduaUtil.http_get_contents_all_cert(url); final String ip = KakaduaUtil.http_get_contents("https://ip.popeen.com/api/"); Log.w("pinging", input); runOnUiThread(new Runnable() { @Override//from ww w . j a va 2 s .c om public void run() { try { JSONObject json = new JSONObject(input); String resp = json.getJSONObject("subsonic-response").getString("booksonic"); Log.w("outdated?", resp); TextView t = (TextView) findViewById(R.id.msg); if (t != null) { if (resp.equals("outdated")) { Log.w(":/", ":/"); t.setText(context.getText(R.string.msg_server_outdated)); t.setVisibility(View.VISIBLE); } else if (resp.equals("outdated_beta") || resp.equals("true")) { //early beta versions only returned "true" Log.w(":(", ":("); t.setText(context.getText(R.string.msg_server_outdated_beta)); t.setVisibility(View.VISIBLE); } else { Log.w(":)", ":)"); t.setVisibility(View.INVISIBLE); try { resp = json.getJSONObject("subsonic-response").getString("emulator"); t.setText("Server Emulator: " + resp.toString()); t.setVisibility(View.VISIBLE); } catch (Exception e) { } } } } catch (Exception er) { TextView t = (TextView) findViewById(R.id.msg); if (t != null) { Log.w("Network Error", er.toString()); if (er.toString().contains("End of input at character 0")) { try { JSONObject ipJson = new JSONObject(ip); String ipResp = ipJson.getString("ip"); t.setText(context.getText(R.string.msg_server_offline)); } catch (Exception e) { t.setText(context.getText(R.string.msg_noInternet)); } t.setVisibility(View.VISIBLE); } else { t.setText(context.getText(R.string.msg_server_notBooksonic)); t.setVisibility(View.VISIBLE); } } } } }); } }).start(); } }
From source file:com.sdspikes.fireworks.FireworksActivity.java
private TextView makeAttributeTextView(final int rank, final GameState.CardColor color) { LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT); int oneButtonWidth = mDiscardWidthR2 / 10; int marginWidth = oneButtonWidth / 10; params.setMargins(marginWidth, 5, marginWidth, 5); params.width = oneButtonWidth - marginWidth * 2; params.height = params.width;/*from w ww . ja va2s. c om*/ TextView textView = new TextView(this); textView.setLayoutParams(params); textView.setText(String.valueOf(rank)); if (rank == -1) textView.setText(" "); textView.setGravity(Gravity.CENTER); textView.setBackgroundResource(HandFragment.cardColorToBGColor.get(color)); textView.setTextColor(getResources().getColor(HandFragment.cardColorToTextColor(color))); textView.setVisibility(View.VISIBLE); textView.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Log.d(TAG, "clicked on an attribute button: " + GameState.Card.cardColorToString(color) + " " + rank); List<GameState.Card> hand = mTurnData.state.hands.get(mRecipientPlayer).hand; List<Integer> locations = new ArrayList<Integer>(); String info = ""; if (rank == -1) { info = GameState.Card.cardColorToString(color); for (int i = 0; i < hand.size(); i++) { if (hand.get(i).color == color) locations.add(i); } } else { info = HandFragment.rankToString(rank); for (int i = 0; i < hand.size(); i++) { if (hand.get(i).rank == rank) locations.add(i); } } if (locations.size() == 0) { Toast.makeText(FireworksActivity.this, mIdToName.get(mRecipientPlayer) + " does not have any " + info, Toast.LENGTH_SHORT); } else { int[] positions = new int[locations.size()]; for (int i = 0; i < positions.length; i++) { // Make the positions 1-indexed positions[i] = locations.get(i) + 1; } LogItem item = new InfoLogItem(mMyId, mRecipientPlayer, info, positions); actionLog.add(item.toString()); mTurnData.state.hintsRemaining--; mTurnData.state.currentPlayerId = mTurnData.state.hands .get(mTurnData.state.currentPlayerId).nextPlayerId; togglePlayOptionsVisible(PlayOptions.turnMessage); broadcastGameInfo(item.getJSONObject()); updateAllPlayers(mTurnData.getJSONObject()); mRecipientPlayer = null; } } }); return textView; }
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;/*w ww.j a va2 s . c om*/ } 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.digitalarx.android.authentication.AuthenticatorActivity.java
/** * Configures elements in the user interface under direct control of the Activity. * /*from w w w . ja v a 2s . c om*/ * @param savedInstanceState Saved activity state, as in {{@link #onCreate(Bundle)} */ private void initOverallUi(Bundle savedInstanceState) { /// step 1 - load and process relevant inputs (resources, intent, savedInstanceState) boolean isWelcomeLinkVisible = getResources().getBoolean(R.bool.show_welcome_link); String instructionsMessageText = null; if (mAction == ACTION_UPDATE_EXPIRED_TOKEN) { if (AccountTypeUtils.getAuthTokenTypeAccessToken(MainApp.getAccountType()).equals(mAuthTokenType)) { instructionsMessageText = getString(R.string.auth_expired_oauth_token_toast); } else if (AccountTypeUtils.getAuthTokenTypeSamlSessionCookie(MainApp.getAccountType()) .equals(mAuthTokenType)) { instructionsMessageText = getString(R.string.auth_expired_saml_sso_token_toast); } else { instructionsMessageText = getString(R.string.auth_expired_basic_auth_toast); } } /// step 2 - set properties of UI elements (text, visibility, enabled...) Button welcomeLink = (Button) findViewById(R.id.welcome_link); welcomeLink.setVisibility(isWelcomeLinkVisible ? View.VISIBLE : View.GONE); welcomeLink.setText(String.format(getString(R.string.auth_register), getString(R.string.app_name))); TextView instructionsView = (TextView) findViewById(R.id.instructions_message); if (instructionsMessageText != null) { instructionsView.setVisibility(View.VISIBLE); instructionsView.setText(instructionsMessageText); } else { instructionsView.setVisibility(View.GONE); } }