Example usage for android.widget ViewSwitcher getDisplayedChild

List of usage examples for android.widget ViewSwitcher getDisplayedChild

Introduction

In this page you can find the example usage for android.widget ViewSwitcher getDisplayedChild.

Prototype

public int getDisplayedChild() 

Source Link

Document

Returns the index of the currently displayed child view.

Usage

From source file:com.friedran.appengine.dashboard.gui.DashboardLoadFragment.java

private void switchChartToProgress(View chartView) {
    ViewSwitcher switcher = (ViewSwitcher) chartView.findViewById(R.id.load_chart_switcher);
    if (switcher.getDisplayedChild() != 0) {
        switcher.showPrevious();//from   w w w.j  av  a  2s  .  c om
    }
}

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);/*from  w w w .j a  v a 2 s  .com*/
    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:com.friedran.appengine.dashboard.gui.DashboardLoadFragment.java

private void updateChartImage(View chartView, Bitmap image, boolean animate) {
    ImageView chartImageView = (ImageView) chartView.findViewById(R.id.load_chart_image);

    if (image != null) {
        chartImageView.setImageBitmap(image);
    } else {/*from w ww  .ja  v a2 s . co  m*/
        chartImageView.setImageResource(android.R.color.transparent);
        Toast.makeText(mActivity,
                "Failed downloading charts, please make sure you have Internet connectivity and try refreshing",
                2000).show();
    }

    ViewSwitcher viewSwitcher = (ViewSwitcher) chartView.findViewById(R.id.load_chart_switcher);
    if (viewSwitcher.getDisplayedChild() != 1) {
        if (animate) {
            viewSwitcher.setAnimation(AnimationUtils.loadAnimation(mActivity, R.anim.fadein));
        } else
            viewSwitcher.setAnimation(null);
        viewSwitcher.showNext();
    }

    // Mark the refresh UI as complete once anyone of the charts has been loaded.
    mPullToRefreshAttacher.setRefreshComplete();
}

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  www  .  ja v 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:de.baumann.thema.RequestActivity.java

@SuppressWarnings("unchecked")
private void populateView(ArrayList arrayListFinal) {
    ArrayList<AppInfo> local_arrayList;
    local_arrayList = arrayListFinal;// w  w  w .j av a2 s  .c  o  m

    GridView grid = (GridView) findViewById(R.id.appgrid);

    assert grid != null;
    grid.setVerticalSpacing(GridView.AUTO_FIT);
    grid.setHorizontalSpacing(GridView.AUTO_FIT);
    grid.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
    grid.setFastScrollEnabled(true);
    grid.setFastScrollAlwaysVisible(true);

    if (DEBUG)
        Log.v(TAG, "height: " + getDisplaySize("height") + "; width: " + getDisplaySize("width"));

    AppAdapter appInfoAdapter;
    if (isPortrait()) {
        grid.setNumColumns(numCol_Portrait);

        if (isTablet(context)) {
            grid.setNumColumns(numCol_Portrait); //Here you can change the number of columns for Tablets
            if (DEBUG)
                Log.v(TAG, "isTablet");
        }
        if (isXLargeTablet(context)) {
            grid.setNumColumns(numCol_Portrait); //Here you can change the number of columns for Large Tablets
            if (DEBUG)
                Log.v(TAG, "isXLargeTablet");
        }

        appInfoAdapter = new AppAdapter(this, R.layout.request_item_list, local_arrayList);
    }

    else {
        grid.setNumColumns(numCol_Landscape);

        if (isTablet(context)) {
            grid.setNumColumns(numCol_Landscape); //Here you can change the number of columns for Tablets
            if (DEBUG)
                Log.v(TAG, "isTablet");
        }
        if (isXLargeTablet(context)) {
            grid.setNumColumns(numCol_Landscape); //Here you can change the number of columns for Large Tablets
            if (DEBUG)
                Log.v(TAG, "isXLargeTablet");
        }

        appInfoAdapter = new AppAdapter(this, R.layout.request_item_grid, local_arrayList);
    }

    grid.setAdapter(appInfoAdapter);
    grid.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        public void onItemClick(AdapterView<?> AdapterView, View view, int position, long row) {
            AppInfo appInfo = (AppInfo) AdapterView.getItemAtPosition(position);
            CheckBox checker = (CheckBox) view.findViewById(R.id.CBappSelect);
            ViewSwitcher icon = (ViewSwitcher) view.findViewById(R.id.viewSwitcherChecked);
            LinearLayout localBackground = (LinearLayout) view.findViewById(R.id.card_bg);
            Animation aniIn = AnimationUtils.loadAnimation(context, R.anim.request_flip_in_half_1);
            Animation aniOut = AnimationUtils.loadAnimation(context, R.anim.request_flip_in_half_2);

            checker.toggle();
            appInfo.setSelected(checker.isChecked());

            icon.setInAnimation(aniIn);
            icon.setOutAnimation(aniOut);

            if (appInfo.isSelected()) {
                if (DEBUG)
                    Log.v(TAG, "Selected App: " + appInfo.getName());
                localBackground
                        .setBackgroundColor(ContextCompat.getColor(context, R.color.request_card_pressed));
                if (icon.getDisplayedChild() == 0) {
                    icon.showNext();
                }
            } else {
                if (DEBUG)
                    Log.v(TAG, "Deselected App: " + appInfo.getName());
                localBackground
                        .setBackgroundColor(ContextCompat.getColor(context, R.color.request_card_unpressed));
                if (icon.getDisplayedChild() == 1) {
                    icon.showPrevious();
                }
            }
        }
    });
}