List of usage examples for android.widget ViewSwitcher setDisplayedChild
@android.view.RemotableViewMethod public void setDisplayedChild(int whichChild)
From source file:Main.java
/** * Build UI From Network Issue for PreExecute. * @param viewSwitcher/* w ww . j av a2s. co m*/ * @param displayChildIndex */ public static void buildUiFromNetworkIssueForPreExecute(final ViewSwitcher viewSwitcher, int displayChildIndex) { if (viewSwitcher == null) { return; } // TextView tvMessage = (TextView) viewSwitcher.findViewById(R.id.tvUiFromNetworkIssueMessage); // ProgressBar pbProgress = (ProgressBar) viewSwitcher.findViewById(R.id.pbUiFromNetworkIssueProgress); // if(pbProgress != null) { // pbProgress.setVisibility(View.VISIBLE); // } // if(tvMessage != null) { // tvMessage.setVisibility(View.GONE); // } viewSwitcher.setDisplayedChild(displayChildIndex); }
From source file:com.tweetlanes.android.core.view.DirectMessageActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); configureActionBarView();/* w ww . j av a2 s . c o m*/ ViewSwitcher viewSwitcher = (ViewSwitcher) findViewById(R.id.rootViewSwitcher); viewSwitcher.reset(); viewSwitcher.setDisplayedChild(1); setDirectMessageOtherUserScreenName(getOtherUserScreenName()); }
From source file:com.renard.ocr.documents.viewing.single.DocumentTextFragment.java
@Override public void onViewStateRestored(@Nullable Bundle savedInstanceState) { super.onViewStateRestored(savedInstanceState); String text = getArguments().getString("text"); ViewSwitcher viewSwitcher = (ViewSwitcher) getView().findViewById(R.id.viewSwitcher); if (savedInstanceState == null || !savedInstanceState.getBoolean(IS_STATE_SAVED)) { mHtmlTask = new HtmlToSpannedAsyncTask(mEditText, viewSwitcher, this); mHtmlTask.execute(text);/* www.j a v a 2 s . c om*/ } else { viewSwitcher.setDisplayedChild(1); mEditText.addTextChangedListener(this); } }
From source file:net.kourlas.voipms_sms.activities.ConversationQuickReplyActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.conversation_quick_reply); database = Database.getInstance(getApplicationContext()); preferences = Preferences.getInstance(getApplicationContext()); contact = getIntent().getExtras().getString(getString(R.string.conversation_extra_contact)); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar);//w ww .ja v a 2s. c o m ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { actionBar.setHomeButtonEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); actionBar.setDisplayShowTitleEnabled(false); } NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Integer notificationId = Notifications.getInstance(getApplicationContext()).getNotificationIds() .get(contact); if (notificationId != null) { manager.cancel(notificationId); } TextView replyToText = (TextView) findViewById(R.id.reply_to_edit_text); String contactName = Utils.getContactName(getApplicationContext(), contact); if (contactName == null) { replyToText.setText(getString(R.string.conversation_quick_reply_reply_to) + " " + Utils.getFormattedPhoneNumber(contact)); } else { replyToText.setText(getString(R.string.conversation_quick_reply_reply_to) + " " + contactName); } final EditText messageText = (EditText) findViewById(R.id.message_edit_text); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { messageText.setOutlineProvider(new ViewOutlineProvider() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void getOutline(View view, Outline outline) { outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), 15); } }); messageText.setClipToOutline(true); } messageText.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) { ViewSwitcher viewSwitcher = (ViewSwitcher) findViewById(R.id.view_switcher); if (s.toString().equals("") && viewSwitcher.getDisplayedChild() == 1) { viewSwitcher.setDisplayedChild(0); } else if (viewSwitcher.getDisplayedChild() == 0) { viewSwitcher.setDisplayedChild(1); } } }); QuickContactBadge photo = (QuickContactBadge) findViewById(R.id.photo); Utils.applyCircularMask(photo); photo.assignContactFromPhone(Preferences.getInstance(getApplicationContext()).getDid(), true); Uri uri = Uri.withAppendedPath(ContactsContract.PhoneLookup.CONTENT_FILTER_URI, Uri.encode(Preferences.getInstance(getApplicationContext()).getDid())); Cursor cursor = getContentResolver().query(uri, new String[] { ContactsContract.PhoneLookup._ID, ContactsContract.PhoneLookup.PHOTO_THUMBNAIL_URI, ContactsContract.PhoneLookup.DISPLAY_NAME }, null, null, null); if (cursor.moveToFirst()) { String photoUri = cursor .getString(cursor.getColumnIndex(ContactsContract.Contacts.PHOTO_THUMBNAIL_URI)); if (photoUri != null) { photo.setImageURI(Uri.parse(photoUri)); } else { photo.setImageToDefault(); } } else { photo.setImageToDefault(); } cursor.close(); final ImageButton sendButton = (ImageButton) findViewById(R.id.send_button); Utils.applyCircularMask(sendButton); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { preSendMessage(); } }); Button openAppButton = (Button) findViewById(R.id.open_app_button); openAppButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { finish(); Intent intent = new Intent(activity, ConversationActivity.class); intent.putExtra(getString(R.string.conversation_extra_contact), contact); TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext()); stackBuilder.addParentStack(ConversationActivity.class); stackBuilder.addNextIntent(intent); stackBuilder.startActivities(); } }); messageText.requestFocus(); }
From source file:net.kourlas.voipms_sms.adapters.ConversationsRecyclerViewAdapter.java
@Override public void onBindViewHolder(ConversationViewHolder conversationViewHolder, int position) { Message message = messages.get(position); ViewSwitcher viewSwitcher = conversationViewHolder.getViewSwitcher(); viewSwitcher.setDisplayedChild(isItemChecked(position) ? 1 : 0); QuickContactBadge contactBadge = conversationViewHolder.getContactBadge(); contactBadge.assignContactFromPhone(message.getContact(), true); String photoUri = Utils.getContactPhotoUri(applicationContext, message.getContact()); if (photoUri != null) { contactBadge.setImageURI(Uri.parse(photoUri)); } else {//w w w . j a v a 2s .c o m contactBadge.setImageToDefault(); } TextView contactTextView = conversationViewHolder.getContactTextView(); String contactName = Utils.getContactName(applicationContext, message.getContact()); SpannableStringBuilder contactTextBuilder = new SpannableStringBuilder(); if (contactName != null) { contactTextBuilder.append(contactName); } else { contactTextBuilder.append(Utils.getFormattedPhoneNumber(message.getContact())); } if (!filterConstraint.equals("")) { int index = contactTextBuilder.toString().toLowerCase().indexOf(filterConstraint.toLowerCase()); if (index != -1) { contactTextBuilder.setSpan( new BackgroundColorSpan(ContextCompat.getColor(applicationContext, R.color.highlight)), index, index + filterConstraint.length(), SpannableString.SPAN_INCLUSIVE_EXCLUSIVE); } } contactTextView.setText(contactTextBuilder); final TextView messageTextView = conversationViewHolder.getMessageTextView(); SpannableStringBuilder messageTextBuilder = new SpannableStringBuilder(); int index = message.getText().toLowerCase().indexOf(filterConstraint.toLowerCase()); if (!filterConstraint.equals("") && index != -1) { int nonMessageOffset = index; if (message.getType() == Message.Type.OUTGOING) { messageTextBuilder.insert(0, applicationContext.getString(R.string.conversations_message_you) + " "); nonMessageOffset += 5; } int substringOffset = index - 20; if (substringOffset > 0) { messageTextBuilder.append("..."); nonMessageOffset += 3; while (message.getText().charAt(substringOffset) != ' ' && substringOffset < index - 1) { substringOffset += 1; } substringOffset += 1; } else { substringOffset = 0; } messageTextBuilder.append(message.getText().substring(substringOffset)); messageTextBuilder.setSpan( new BackgroundColorSpan(ContextCompat.getColor(applicationContext, R.color.highlight)), nonMessageOffset - substringOffset, nonMessageOffset - substringOffset + filterConstraint.length(), SpannableString.SPAN_INCLUSIVE_EXCLUSIVE); } else { if (message.getType() == Message.Type.OUTGOING) { messageTextBuilder.append(applicationContext.getString(R.string.conversations_message_you)); messageTextBuilder.append(" "); } messageTextBuilder.append(message.getText()); } messageTextView.setText(messageTextBuilder); if (message.isUnread()) { contactTextView.setTypeface(null, Typeface.BOLD); messageTextView.setTypeface(null, Typeface.BOLD); } else { contactTextView.setTypeface(null, Typeface.NORMAL); messageTextView.setTypeface(null, Typeface.NORMAL); } // Set date line TextView dateTextView = conversationViewHolder.getDateTextView(); if (message.isDraft()) { SpannableStringBuilder dateTextBuilder = new SpannableStringBuilder(); dateTextBuilder.append(applicationContext.getString(R.string.conversations_message_draft)); dateTextBuilder.setSpan(new StyleSpan(Typeface.ITALIC), 0, dateTextBuilder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); dateTextView.setText(dateTextBuilder); } else if (!message.isDelivered()) { if (!message.isDeliveryInProgress()) { SpannableStringBuilder dateTextBuilder = new SpannableStringBuilder(); dateTextBuilder.append(applicationContext.getString(R.string.conversations_message_not_sent)); dateTextBuilder.setSpan( new ForegroundColorSpan( ContextCompat.getColor(applicationContext, android.R.color.holo_red_dark)), 0, dateTextBuilder.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); dateTextView.setText(dateTextBuilder); } else { dateTextView.setText(applicationContext.getString(R.string.conversations_message_sending)); } } else { dateTextView.setText(Utils.getFormattedDate(applicationContext, message.getDate(), true)); } }
From source file:net.kourlas.voipms_sms.activities.ConversationActivity.java
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.conversation); database = Database.getInstance(getApplicationContext()); preferences = Preferences.getInstance(getApplicationContext()); contact = getIntent().getStringExtra(getString(R.string.conversation_extra_contact)); // Remove the leading one from a North American phone number (e.g. +1 (123) 555-4567) if ((contact.length() == 11) && (contact.charAt(0) == '1')) { contact = contact.substring(1);/*from ww w . j av a 2 s .c om*/ } Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); ViewCompat.setElevation(toolbar, getResources().getDimension(R.dimen.toolbar_elevation)); setSupportActionBar(toolbar); ActionBar actionBar = getSupportActionBar(); if (actionBar != null) { String contactName = Utils.getContactName(this, contact); if (contactName != null) { actionBar.setTitle(contactName); } else { actionBar.setTitle(Utils.getFormattedPhoneNumber(contact)); } actionBar.setHomeButtonEnabled(true); actionBar.setDisplayHomeAsUpEnabled(true); } layoutManager = new LinearLayoutManager(this); layoutManager.setOrientation(LinearLayoutManager.VERTICAL); layoutManager.setStackFromEnd(true); adapter = new ConversationRecyclerViewAdapter(this, layoutManager, contact); recyclerView = (RecyclerView) findViewById(R.id.list); recyclerView.setHasFixedSize(true); recyclerView.setLayoutManager(layoutManager); recyclerView.setAdapter(adapter); actionMode = null; actionModeEnabled = false; final EditText messageText = (EditText) findViewById(R.id.message_edit_text); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { messageText.setOutlineProvider(new ViewOutlineProvider() { @TargetApi(Build.VERSION_CODES.LOLLIPOP) @Override public void getOutline(View view, Outline outline) { outline.setRoundRect(0, 0, view.getWidth(), view.getHeight(), 15); } }); messageText.setClipToOutline(true); } messageText.addTextChangedListener(new TextWatcher() { @Override public void beforeTextChanged(CharSequence s, int start, int count, int after) { // Do nothing. } @Override public void onTextChanged(CharSequence s, int start, int before, int count) { // Do nothing. } @Override public void afterTextChanged(Editable s) { ViewSwitcher viewSwitcher = (ViewSwitcher) findViewById(R.id.view_switcher); if (s.toString().equals("") && viewSwitcher.getDisplayedChild() == 1) { viewSwitcher.setDisplayedChild(0); } else if (viewSwitcher.getDisplayedChild() == 0) { viewSwitcher.setDisplayedChild(1); } } }); messageText.setOnFocusChangeListener(new View.OnFocusChangeListener() { @Override public void onFocusChange(View v, boolean hasFocus) { if (hasFocus) { adapter.refresh(); } } }); String intentMessageText = getIntent().getStringExtra(getString(R.string.conversation_extra_message_text)); if (intentMessageText != null) { messageText.setText(intentMessageText); } boolean intentFocus = getIntent().getBooleanExtra(getString(R.string.conversation_extra_focus), false); if (intentFocus) { messageText.requestFocus(); } RelativeLayout messageSection = (RelativeLayout) findViewById(R.id.message_section); ViewCompat.setElevation(messageSection, 8); QuickContactBadge photo = (QuickContactBadge) findViewById(R.id.photo); Utils.applyCircularMask(photo); photo.assignContactFromPhone(preferences.getDid(), true); String photoUri = Utils.getContactPhotoUri(getApplicationContext(), preferences.getDid()); if (photoUri != null) { photo.setImageURI(Uri.parse(photoUri)); } else { photo.setImageToDefault(); } final ImageButton sendButton = (ImageButton) findViewById(R.id.send_button); Utils.applyCircularMask(sendButton); sendButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { preSendMessage(); } }); }
From source file:tr.com.turkcellteknoloji.turkcellupdater.UpdaterDialogManager.java
@SuppressLint("NewApi") private static View createMessageDialogContentsView(Activity activity, MessageDescription messageDescription) { Context context = activity;//from w w w .j a v a 2s . co m final AlertDialog.Builder builder; // Workaround for dialog theme problems if (android.os.Build.VERSION.SDK_INT > 10) { builder = new AlertDialog.Builder(context); context = builder.getContext(); } else { context = new ContextThemeWrapper(context, android.R.style.Theme_Dialog); builder = new AlertDialog.Builder(context); } builder.setTitle("Send feedback"); final LayoutInflater inflater = LayoutInflater.from(context); final View dialogContentsView = inflater.inflate(R.layout.updater_dialog_message, null, false); final TextView textView = (TextView) dialogContentsView.findViewById(R.id.dialog_update_message_text); final ImageView imageView = (ImageView) dialogContentsView.findViewById(R.id.dialog_update_message_image); final ViewSwitcher switcher = (ViewSwitcher) dialogContentsView .findViewById(R.id.dialog_update_message_switcher); String messageText = null; String imageUrl = null; if (messageDescription != null) { messageText = messageDescription.get(MessageDescription.KEY_MESSAGE); imageUrl = messageDescription.get(MessageDescription.KEY_IMAGE_URL); } if (Utilities.isNullOrEmpty(messageText)) { textView.setVisibility(View.GONE); } else { textView.setText(messageText); } if (Utilities.isNullOrEmpty(imageUrl)) { switcher.setVisibility(View.GONE); } else { URI uri; try { uri = new URI(imageUrl); } catch (URISyntaxException e) { uri = null; } if (uri != null) { DownloadRequest request = new DownloadRequest(); request.setUri(uri); request.setDownloadHandler(new DownloadHandler() { @Override public void onSuccess(byte[] result) { // Load image from byte array final Bitmap bitmap = BitmapFactory.decodeByteArray(result, 0, result.length); imageView.setImageBitmap(bitmap); // Hide progress bar and display image if (switcher != null) { switcher.setDisplayedChild(1); } } @Override public void onProgress(Integer percent) { } @Override public void onFail(Exception ex) { Log.e("Message image couldn't be loaded", ex); } @Override public void onCancelled() { } }); HttpClient client = Utilities.createClient("Turkcell Updater/1.0 ", false); try { request.executeAsync(client); } catch (Exception e) { Log.e("Message image couldn't be loaded", e); } } else { switcher.setVisibility(View.GONE); } } return dialogContentsView; }